teslamate
teslamate copied to clipboard
Grafana is unable to connect to the database
Is there an existing issue for this?
- [X] I have searched the existing issues
What happened?
Grafana is unable to connect to the database
Error updating options: error when executing the sql query
Expected Behavior
No response
Steps To Reproduce
1.centos 2.docker-compose.yaml 3.api token 4.Dashboards
Relevant log output
teslamate
2024-04-25 08:49:59.959 [info] Starting logger for '宝宝巴士'
2024-04-25 08:50:00.055 car_id=1 [error] Error / not_signed_in
2024-04-25 08:50:00.098 [info] MQTT connection has been established
2024-04-25 08:50:06.216 [info] GET /
2024-04-25 08:50:06.253 [info] Sent 302 in 36ms
2024-04-25 08:50:06.285 [info] GET /sign_in
2024-04-25 08:50:06.306 [info] Sent 200 in 21ms
2024-04-25 08:50:22.139 [info] GET /
2024-04-25 08:50:22.143 [info] Sent 302 in 3ms
2024-04-25 08:50:22.173 [info] GET /sign_in
2024-04-25 08:50:22.177 [info] Sent 200 in 4ms
2024-04-25 08:50:33.955 [info] POST https://auth.tesla.cn/oauth2/v3/token -> 200 (302.297 ms)
2024-04-25 08:50:33.975 [info] Scheduling token refresh in 6 h
2024-04-25 08:50:34.265 [info] GET /
2024-04-25 08:50:35.225 [info] Starting logger for '宝宝巴士'
2024-04-25 08:50:35.251 [info] Sent 200 in 985ms
2024-04-25 08:50:35.638 car_id=1 [info] Start / :online
2024-04-25 08:50:35.644 car_id=1 [info] Logged missing software update: 2024.2.9 694bd7f04f4a
2024-04-25 08:50:35.816 car_id=1 [info] Connecting ...
2024-04-25 08:50:35.817 [info] Start of drive initiated by: %TeslaApi.Vehicle.State.Drive{active_route_destination: nil, active_route_energy_at_arrival: nil, active_route_latitude: 27.83232, active_route_longitude: 112.936641, active_route_miles_to_arrival: nil, active_route_minutes_to_arrival: nil, active_route_traffic_minutes_delay: 0.0, gps_as_of: 1714035033, heading: 118, latitude: 27.909357, longitude: 112.543829, native_latitude: 27.905904, native_location_supported: 1, native_longitude: 112.54918, native_type: "gcj", power: 1, shift_state: "D", speed: 0, timestamp: 1714035035058}
2024-04-25 08:50:35.817 car_id=1 [info] Driving / Start
2024-04-25 08:51:12.546 [info] GET /
2024-04-25 08:51:12.548 [info] Sent 200 in 2ms
2024-04-25 08:51:41.334 [info] GET /
2024-04-25 08:51:41.336 [info] Sent 200 in 2ms
2024-04-25 08:54:09.001 [info] GET /
2024-04-25 08:54:09.003 [info] Sent 200 in 2ms
grafana
logger=ngalert.migration t=2024-04-25T09:02:16.126720639Z level=info msg=Starting
logger=ngalert.state.manager t=2024-04-25T09:02:16.147488525Z level=info msg="Running in alternative execution of Error/NoData mode"
logger=infra.usagestats.collector t=2024-04-25T09:02:16.149826947Z level=info msg="registering usage stat providers" usageStatsProvidersLen=2
logger=provisioning.alerting t=2024-04-25T09:02:16.172667984Z level=info msg="starting to provision alerting"
logger=provisioning.alerting t=2024-04-25T09:02:16.172694968Z level=info msg="finished to provision alerting"
logger=ngalert.state.manager t=2024-04-25T09:02:16.173211027Z level=info msg="Warming state cache for startup"
logger=ngalert.state.manager t=2024-04-25T09:02:16.173614885Z level=info msg="State cache has been initialized" states=0 duration=402.461µs
logger=http.server t=2024-04-25T09:02:16.175894529Z level=info msg="HTTP Server Listen" address=[::]:3000 protocol=http subUrl= socket=
logger=grafanaStorageLogger t=2024-04-25T09:02:16.175988511Z level=info msg="Storage starting"
logger=provisioning.dashboard t=2024-04-25T09:02:16.177278851Z level=info msg="starting to provision dashboards"
logger=ngalert.multiorg.alertmanager t=2024-04-25T09:02:16.194438568Z level=info msg="Starting MultiOrg Alertmanager"
logger=ngalert.scheduler t=2024-04-25T09:02:16.194477645Z level=info msg="Starting scheduler" tickInterval=10s maxAttempts=1
logger=ticker t=2024-04-25T09:02:16.194534264Z level=info msg=starting first_tick=2024-04-25T09:02:20Z
logger=provisioning.dashboard t=2024-04-25T09:02:16.279732889Z level=info msg="finished to provision dashboards"
logger=context userId=1 orgId=1 uname=admin t=2024-04-25T09:02:16.369558052Z level=info msg="Request Completed" method=GET path=/api/live/ws status=-1 remote_addr=183.215.213.53 time_ms=4 duration=4.908419ms size=0 referer= handler=/api/live/ws status_source=server
logger=live t=2024-04-25T09:02:16.394556444Z level=info msg="Initialized channel handler" channel=grafana/dashboard/uid/FkUpJpQZk address=grafana/dashboard/uid/FkUpJpQZk
logger=context userId=1 orgId=1 uname=admin t=2024-04-25T09:02:16.43616552Z level=info msg="Request Completed" method=GET path=/api/live/ws status=-1 remote_addr=183.215.213.53 time_ms=1 duration=1.709924ms size=0 referer= handler=/api/live/ws status_source=server
logger=live t=2024-04-25T09:02:16.463376425Z level=info msg="Initialized channel handler" channel=grafana/dashboard/uid/ZzhF-aRWz address=grafana/dashboard/uid/ZzhF-aRWz
logger=context userId=1 orgId=1 uname=admin t=2024-04-25T09:02:16.502895416Z level=info msg="Request Completed" method=GET path=/api/live/ws status=-1 remote_addr=183.215.213.53 time_ms=2 duration=2.229595ms size=0 referer= handler=/api/live/ws status_source=server
logger=live t=2024-04-25T09:02:16.52994921Z level=info msg="Initialized channel handler" channel=grafana/dashboard/uid/TSmNYvRRk address=grafana/dashboard/uid/TSmNYvRRk
logger=context userId=1 orgId=1 uname=admin t=2024-04-25T09:02:16.569324647Z level=info msg="Request Completed" method=GET path=/api/live/ws status=-1 remote_addr=183.215.213.53 time_ms=2 duration=2.374144ms size=0 referer= handler=/api/live/ws status_source=server
logger=live t=2024-04-25T09:02:16.594981822Z level=info msg="Initialized channel handler" channel=grafana/dashboard/uid/jchmRiqUfXgTM address=grafana/dashboard/uid/jchmRiqUfXgTM
logger=plugins.update.checker t=2024-04-25T09:02:16.662585292Z level=info msg="Update check succeeded" duration=468.952929ms
logger=grafana-apiserver t=2024-04-25T09:02:16.686354435Z level=info msg="Adding GroupVersion playlist.grafana.app v0alpha1 to ResourceManager"
logger=grafana-apiserver t=2024-04-25T09:02:16.687161946Z level=info msg="Adding GroupVersion featuretoggle.grafana.app v0alpha1 to ResourceManager"
logger=grafana.update.checker t=2024-04-25T09:02:16.701181493Z level=info msg="Update check succeeded" duration=508.313663ms
logger=context userId=1 orgId=1 uname=admin t=2024-04-25T09:02:17.36868936Z level=info msg="Request Completed" method=GET path=/api/live/ws status=-1 remote_addr=183.215.213.53 time_ms=1 duration=1.540841ms size=0 referer= handler=/api/live/ws status_source=server
Screenshots
No response
Additional data
No response
Type of installation
Docker
Version
1.28.5
Can you check whether the tables in your database container are present? Is the database container running?
docker compose -p teslamate exec database psql teslamate teslamate -c '\dt'
List of relations
Schema | Name | Type | Owner
--------+--------------------+-------+-----------
public | addresses | table | teslamate
public | car_settings | table | teslamate
public | cars | table | teslamate
public | charges | table | teslamate
public | charging_processes | table | teslamate
public | drives | table | teslamate
public | geofences | table | teslamate
public | positions | table | teslamate
public | schema_migrations | table | teslamate
public | settings | table | teslamate
public | states | table | teslamate
public | tokens | table | teslamate
public | updates | table | teslamate
(13 rows)
docker compose -p teslamate ps
NAME IMAGE COMMAND SERVICE CREATED STATUS PORTS
teslamate-database-1 postgres:15 "docker-entrypoint.s…" database 4 weeks ago Up 4 days 5432/tcp
teslamate-grafana-1 teslamate/grafana:1.28.5 "/run.sh" grafana 3 weeks ago Up 4 days 0.0.0.0:3000->3000/tcp, :::3000->3000/tcp
teslamate-mosquitto-1 eclipse-mosquitto:2 "/docker-entrypoint.…" mosquitto 4 weeks ago Up 4 days 0.0.0.0:1883->1883/tcp, :::1883->1883/tcp
teslamate-teslamate-1 teslamate/teslamate:1.28.5 "tini -- /bin/sh /en…" teslamate 3 weeks ago Up 4 days 0.0.0.0:4000->4000/tcp, :::4000->4000/tcp
similar problems here, for example the following error in my teslamate-db-log: All containers up and running, no changes in db. After a simple browser refresh, it works without errors.
PostgreSQL Database directory appears to contain a database; Skipping initialization 2024-05-05 21:23:02.504 UTC [1] LOG: starting PostgreSQL 15.6 (Debian 15.6-1.pgdg120+2) on aarch64-unknown-linux-gnu, compiled by gcc (Debian 12.2.0-14) 12.2.0, 64-bit 2024-05-05 21:23:02.509 UTC [1] LOG: listening on IPv4 address "0.0.0.0", port 5432 2024-05-05 21:23:02.509 UTC [1] LOG: listening on IPv6 address "::", port 5432 2024-05-05 21:23:02.524 UTC [1] LOG: listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432" 2024-05-05 21:23:02.539 UTC [28] LOG: database system was shut down at 2024-05-05 21:22:51 UTC 2024-05-05 21:23:02.554 UTC [1] LOG: database system is ready to accept connections 2024-05-05 21:28:02.630 UTC [26] LOG: checkpoint starting: time 2024-05-05 21:28:03.049 UTC [26] LOG: checkpoint complete: wrote 7 buffers (0.0%); 0 WAL file(s) added, 0 removed, 0 recycled; write=0.407 s, sync=0.003 s, total=0.419 s; sync files=4, longest=0.002 s, average=0.001 s; distance=7 kB, estimate=7 kB 2024-05-05 22:08:02.738 UTC [26] LOG: checkpoint starting: time 2024-05-05 22:08:03.054 UTC [26] LOG: checkpoint complete: wrote 3 buffers (0.0%); 0 WAL file(s) added, 0 removed, 0 recycled; write=0.303 s, sync=0.002 s, total=0.317 s; sync files=2, longest=0.002 s, average=0.001 s; distance=2 kB, estimate=7 kB 2024-05-06 03:28:06.874 UTC [26] LOG: checkpoint starting: time 2024-05-06 03:28:06.988 UTC [26] LOG: checkpoint complete: wrote 2 buffers (0.0%); 0 WAL file(s) added, 0 removed, 0 recycled; write=0.102 s, sync=0.002 s, total=0.115 s; sync files=2, longest=0.002 s, average=0.001 s; distance=4 kB, estimate=7 kB 2024-05-06 09:23:12.645 UTC [26] LOG: checkpoint starting: time 2024-05-06 09:23:12.757 UTC [26] LOG: checkpoint complete: wrote 2 buffers (0.0%); 0 WAL file(s) added, 0 removed, 0 recycled; write=0.102 s, sync=0.002 s, total=0.113 s; sync files=2, longest=0.002 s, average=0.001 s; distance=6 kB, estimate=6 kB 2024-05-06 13:42:35.629 UTC [3022] ERROR: syntax error at or near "AND" at character 2703 2024-05-06 13:42:35.629 UTC [3022] STATEMENT: WITH data AS ( T round(extract(epoch FROM start_date)) * 1000 AS start_date_ts, round(extract(epoch FROM end_date)) * 1000 AS end_date_ts, car.id as car_id, CASE WHEN start_geofence.id IS NULL THEN CONCAT('new?lat=', start_position.latitude, '&lng=', start_position.longitude) WHEN start_geofence.id IS NOT NULL THEN CONCAT(start_geofence.id, '/edit') END as start_path, CASE WHEN end_geofence.id IS NULL THEN CONCAT('new?lat=', end_position.latitude, '&lng=', end_position.longitude) WHEN end_geofence.id IS NOT NULL THEN CONCAT(end_geofence.id, '/edit') END as end_path, TO_CHAR((duration_min * INTERVAL '1 minute'), 'HH24:MI') as duration_str, drives.id as drive_id, -- Columns start_date, COALESCE(start_geofence.name, CONCAT_WS(', ', COALESCE(start_address.name, nullif(CONCAT_WS(' ', start_address.road, start_address.house_number), '')), start_address.city)) AS start_address, COALESCE(end_geofence.name, CONCAT_WS(', ', COALESCE(end_address.name, nullif(CONCAT_WS(' ', end_address.road, end_address.house_number), '')), end_address.city)) AS end_address, duration_min, distance, start_position.usable_battery_level as start_usable_battery_level, start_position.battery_level as start_battery_level, end_position.usable_battery_level as end_usable_battery_level, end_position.battery_level as end_battery_level, case when (start_position.battery_level != start_position.usable_battery_level OR end_position.battery_level != end_position.usable_battery_level) = true then true else false end as reduced_range, duration_min > 1 AND distance > 1 AND ( start_position.usable_battery_level IS NULL OR end_position.usable_battery_level IS NULL OR (end_position.battery_level - end_position.usable_battery_level) = 0 ) as is_sufficiently_precise, NULLIF(GREATEST(start_rated_range_km - end_rated_range_km, 0), 0) as range_diff, car.efficiency as car_efficiency, outside_temp_avg, distance / NULLIF(duration_min, 0) * 60 AS avg_speed, power_max FROM drives LEFT JOIN addresses start_address ON start_address_id = start_address.id LEFT JOIN addresses end_address ON end_address_id = end_address.id LEFT JOIN positions start_position ON start_position_id = start_position.id LEFT JOIN positions end_position ON end_position_id = end_position.id LEFT JOIN geofences start_geofence ON start_geofence_id = start_geofence.id LEFT JOIN geofences end_geofence ON end_geofence_id = end_geofence.id LEFT JOIN cars car ON car.id = drives.car_id WHERE start_date BETWEEN '2024-04-06T13:42:35.789Z' AND '2024-05-06T13:42:35.789Z' AND drives.car_id = AND convert_km(distance::numeric, 'km') >= 0 AND convert_km(distance::numeric, 'km') / NULLIF(duration_min, 0) * 60 >= 0 ORDER BY start_date DESC ) SELECT start_date_ts, end_date_ts, car_id, start_path, end_path, duration_str, drive_id, -- Columns start_date, start_address, end_address, duration_min, convert_km(distance::numeric, 'km') AS distance_km, start_battery_level as "% Start", end_battery_level as "% End", convert_celsius(outside_temp_avg, 'C') AS outside_temp_C, convert_km(avg_speed::numeric, 'km') AS speed_avg_km, power_max, reduced_range as has_reduced_range, range_diff * car_efficiency as "consumption_kWh", CASE WHEN is_sufficiently_precise THEN range_diff * car_efficiency / distance * 1000 * CASE WHEN 'km' = 'km' THEN 1 WHEN 'km' = 'mi' THEN 1.60934 END END AS consumption_kWh_km, CASE WHEN is_sufficiently_precise THEN distance / range_diff ELSE NULL END AS efficiency FROM data;
This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days if no further activity occurs. Thank you for your contributions.
Hi , i have the same issue. Is there anything what i can do to fix it ?
Same issue there. I have teslamate standalone installation (no docker) with grafana 11 and postgresql 16.
This is Funny, after a few days , it the problem solved by itself. Maybe a Grafana Cloud Problem ?
This is Funny, after a few days , it the problem solved by itself. Maybe a Grafana Cloud Problem ?
@urmeltom within your screenshot I can read something about "McAfee Security". Probably some web traffic analysis/filtering is happening on your client, which prohibits the proper communication to Grafana.