Hi,
I’m using ha and grafana in docker compose. Simply put I can’t access grafana over nabucasa. I have local access to grafana and dashboards but nothing is working if I use remote access over nabu casa cloud.
I tried a lot of things and nothing seems to work.
Has anyone managed to configure grafana in docker compose and access it over nabu casa cloud?
Let me answer to my own question.
I didn’t found a way to access grafana over nabu casa but I did find a way to display grafana dashboards over nabu casa. It is not perfect but it is working. I done my setup mostly based on this post. Obviously using grafana image render plugin can display grafana dashboards as a picture. Not maybe perfect but it is working.
docker-compose.yml
### grafana
grafana:
image: grafana/grafana-enterprise:latest
container_name: grafana
ports:
- 3000:3000
environment:
- TZ=Europe/Zagreb
- GF_AUTH_BASIC_ENABLED=true
- GF_AUTH_DISABLE_LOGIN_FORM=true
- GF_AUTH_ANONYMOUS_ENABLED=true
- GF_AUTH_ANONYMOUS_ORG_ROLE=Admin
- GF_SECURITY_ALLOW_EMBEDDING=true
- GF_RENDERING_SERVER_URL=http://192.168.8.40:8091/render
- GF_RENDERING_CALLBACK_URL=http://192.168.8.40:3000/
- GF_LOG_FILTERS=rendering:debug
healthcheck:
test: curl --fail http://192.168.8.40:3000/ || exit 1
interval: 15s
timeout: 1m
retries: 2
volumes:
- /opt/grafana:/var/lib/grafana
user: "root"
depends_on:
- influxdb
restart: always
### grafana render
renderer:
image: grafana/grafana-image-renderer:latest
container_name: grafana-render
ports:
- 8091:8081
After some tries I found that this setup is working for me.
In configuration.yaml add
### Grafana image
shell_command:
download_grafana_image: '/bin/bash /config/scripts/download_grafana_image.sh'
Create dashboard in grafana, select share and use direct link rendering image. It will open new tab and display whatever you done in grafana. Copy that url.
Create directory scripts, if you don’t have it, and inside that directory create file download_grafana_image.sh with content:
#!/bin/bash
curl -s "URL_you_copied_from_above_refresh=5s&from=24h&to=now&panelId=1&width=1600&height=400" -o /config/www/grafana/my:dashboard_picture.png
Go to the script directory and make file download_grafana_image.sh executable with chmod +s *.sh
Make sure that directory /config/www/grafana exist. If it doesnt create it.
Configure width and height to suit your needs.
Create automation that will call a script every minute or so and do picture update, something like this:
alias: Download grafana image
description: ""
trigger:
- platform: time_pattern
seconds: "30"
condition: []
action:
- service: shell_command.download_grafana_image
metadata: {}
data: {}
mode: single
Check if this is working by running automation and checking if png file is created in grafana directory.
If everything is working you add
camera:
- platform: local_file
name: Grafana_elecricity_current
file_path: /config/www/grafana/electricity.png
After restart home assistant you should have a new camera image.
This is how it looks on a first try
Have you forgotten the hass_ingress? You can get ingress access to grafana through it.
Hi,
I never managed to make it work. I tried everything that I found useful, checked proposed online solutions but nothing is working in my case. This is only solution I was able to make it work.
Many services can implement ingress through some cumbersome configurations. Basically ha addons that support ingress access can implement ingress through hass_ingress, but this process is not universal.
A few days ago I integrated grafana, prometheus and cadvisor into HA sidebar, for grafana you can configure it as follows.
configuration.yaml:
ingress:
grafana:
work_mode: ingress
title: Grafana
icon: mdi:chart-timeline
url: grafana:3000
headers:
X-WEBAUTH-USER: admin
docker-compose.yml:
services:
grafana:
image: grafana/grafana
volumes:
- xx/grafana.ini:/etc/grafana/grafana.ini
grafana.ini:
[server]
root_url = %(protocol)s://%(domain)s:%(http_port)s/api/ingress/grafana/
[security]
allow_embedding = true
[auth.proxy]
enabled = true
header_name = X-WEBAUTH-USER
header_property = username
auto_sign_up = true
Hi,
Thank you for providing this solution. I can access grafana from nabucasa. I tested this on android app and this is working.
For some reason this doesn’t work in google chrome but it does in firefox.
I have one problem. I can’t see data in iframe card when I’m connected over cloud. Card is empty although I can open grafana using your config.
Do you have similar problem?
Hi. I’m just trying to get this working, but have a small snag.
I amusing HA and Ingress as docker containers, with external access to HA via nginx.
Using the config:
ingress:
grafana:
work_mode: ingress
title: Grafana
icon: mdi:chart-timeline
url: grafana:3000
headers:
X-WEBAUTH-USER: admin
I get this issue:
If you’re seeing this Grafana has failed to load its application files
-
This could be caused by your reverse proxy settings.
-
If you host grafana under subpath make sure your grafana.ini root_url setting includes subpath. If not using a reverse proxy make sure to set serve_from_sub_path to true.
-
If you have a local dev build make sure you build frontend using: yarn start, or yarn build
-
Sometimes restarting grafana-server can help
-
Check if you are using a non-supported browser. For more information, refer to the list of supported browsers.
In the ini.
root_url = http://192.168.50.88:23100/
Direct access to the URL works
I have that problem if I use google chrome. With firefox it works,
The root_url and allow_embedding options are required to be set like mine, and these will break direct access.
I just wanted to say thanks, this has fixed it for me. Can I use this to embed individual graphs on other pages now, or just via the sidebar?