jasonacox / Powerwall-Dashboard

Grafana Monitoring Dashboard for Tesla Solar and Powerwall Systems
MIT License
296 stars 63 forks source link

Auto provision InfluxDB data source in Grafana #512

Closed longzheng closed 1 month ago

longzheng commented 1 month ago

Fixes https://github.com/jasonacox/Powerwall-Dashboard/discussions/491

Automatically set up the InfluxDB data source in Grafana.

This hard-codes the URL/port to the default 8086. In theory it might be possible to dynamically update this provisioning YML from INFLUXDB_PORTS in compose.env but it's not that straight forward.

I couldn't reproduce any issues with problems/timeouts as suggested in https://github.com/jasonacox/Powerwall-Dashboard/issues/461. My startup is equally fast with the provisioning file.

I saw these Grafana logs which aren't real errors, they're just indicating there's no provisioned plugins/notifiers/alerts.

2024-08-31 18:39:37 logger=provisioning.plugins t=2024-08-31T08:39:37.485272852Z level=error msg="Failed to read plugin provisioning files from directory" path=/var/lib/grafana/provisions/plugins error="open /var/lib/grafana/provisions/plugins: no such file or directory"
2024-08-31 18:39:37 logger=provisioning.notifiers t=2024-08-31T08:39:37.485794372Z level=error msg="Can't read alert notification provisioning files from directory" path=/var/lib/grafana/provisions/notifiers error="open /var/lib/grafana/provisions/notifiers: no such file or directory"
2024-08-31 18:39:37 logger=provisioning.alerting t=2024-08-31T08:39:37.4865298Z level=error msg="can't read alerting provisioning files from directory" path=/var/lib/grafana/provisions/alerting error="open /var/lib/grafana/provisions/alerting: no such file or directory"
longzheng commented 1 month ago

I tried to auto provision the "sun and moon" data source too but it involves parsing JSON with bash which isn't impossible but not too straight forward so I left that alone for now.

jasonacox commented 1 month ago

Thanks @longzheng ! I'll give it a test.

What instructions do we need to change in setup.sh or README?

I'll play around with the lat/long query to see if we can do that. It would be useful for weather too.

jasonacox commented 1 month ago

I think we can use this in setup.sh and have sun and moon auto provision. It will default to 0/0 and we can add instructions on how to change that data source.

# Get latitude and longitude 
LAT="0.0"
LONG="0.0"
PYTHON=$(command -v python3 || command -v python)
if [ -n "${PYTHON}" ]; then
    LAT=$(curl -s https://freeipapi.com/api/json | "${PYTHON}" -c "import sys, json; print(json.load(sys.stdin)['latitude'])")
    LONG=$(curl -s https://freeipapi.com/api/json | "${PYTHON}" -c "import sys, json; print(json.load(sys.stdin)['longitude'])")
fi

I thought about using jq but many OS variants won't have that installed. Python seems to be more likely.

jasonacox commented 1 month ago

Thanks for this great work @longzheng ! 🙏

I've merged and will be running tests to make sure we didn't break anything. Version v4.5.0.

jasonacox commented 1 month ago

Upgrade notes:

logger=provisioning.plugins t=2024-09-01T15:08:48.063660298Z level=error msg="Failed to read plugin provisioning files from directory" path=/var/lib/grafana/provisions/plugins error="open /var/lib/grafana/provisions/plugins: no such file or directory"
logger=provisioning.notifiers t=2024-09-01T15:08:48.064082276Z level=error msg="Can't read alert notification provisioning files from directory" path=/var/lib/grafana/provisions/notifiers error="open /var/lib/grafana/provisions/notifiers: no such file or directory"
logger=provisioning.alerting t=2024-09-01T15:08:48.064346108Z level=error msg="can't read alerting provisioning files from directory" path=/var/lib/grafana/provisions/alerting error="open /var/lib/grafana/provisions/alerting: no such file or directory"
logger=provisioning.dashboard t=2024-09-01T15:08:48.066779834Z level=error msg="can't read dashboard provisioning files from directory" path=/var/lib/grafana/provisions/dashboards error="open /var/lib/grafana/provisions/dashboards: no such file or directory"
jasonacox commented 1 month ago

New Install Test Notes:

👍