Skip to content

Commit 6173d78

Browse files
committed
Improved error handling/messaging if unable to connect to InfluxDB
1 parent 849d621 commit 6173d78

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

dashboard-writer/inputs.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,12 @@
88
org_id = "influx_org_id"
99

1010
# -----------------------------------------------
11-
# specify devices to process from local/S3. If local files, ensure they are organized as on your SD card
12-
devices = ["LOG/958D2219"] # for S3 use ["bucket_name/serial_no"]
11+
# specify devices to process (from a local folder or S3 bucket)
12+
# If local, ensure files are organized as on SD (folder/device_id/session/split.MF4)
13+
devices = ["LOG/958D2219"] # local: ["folder/device_id"] | S3: ["bucket/device_id"]
1314

1415
# -----------------------------------------------
15-
# specify your DBC path and optionally a specific list of signals to include ([]: use all signals)
16+
# specify DBC path and the list of signals to process ([]: process all signals)
1617
dbc_path = "CSS-Electronics-SAE-J1939-DEMO.dbc"
1718
signals = []
1819

dashboard-writer/utils.py

+22
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,13 @@ def write_influx(name, df):
1515
# initialize client and write to InfluxDB
1616
client = InfluxDBClient(url=inputs.influx_url, token=inputs.token, org=inputs.org_id, debug=False)
1717

18+
# check that InfluxDB bucket is available, then write data to InfluxDB
19+
try:
20+
test = client.query_api().query(f'from(bucket:"{inputs.influx_bucket}") |> range(start: -10s)')
21+
except Exception as err:
22+
print_influx_error(str(err))
23+
return
24+
1825
_write_client = client.write_api(
1926
write_options=WriteOptions(batch_size=5000, flush_interval=10_000, jitter_interval=2_000, retry_interval=5_000,)
2027
)
@@ -124,3 +131,18 @@ def print_summary(device_id, log_file, df_phys):
124131
"\n---------------",
125132
f"\nDevice: {device_id} | Log file: {log_file.split(device_id)[-1]} [Extracted {len(df_phys)} decoded frames]\nPeriod: {df_phys.index.min()} - {df_phys.index.max()}\n",
126133
)
134+
135+
136+
def print_influx_error(err):
137+
warning = "- WARNING: Unable to write data to InfluxDB |"
138+
139+
if "CERTIFICATE_VERIFY_FAILED" in err:
140+
print(f"{warning} check your influx_url ({inputs.influx_url})")
141+
elif "organization name" in err:
142+
print(f"{warning} check your org_id ({inputs.org_id})")
143+
elif "unauthorized access" in err:
144+
print(f"{warning} check your influx_url and token")
145+
elif "could not find bucket" in err:
146+
print(f"{warning} check your influx_bucket ({inputs.influx_bucket})")
147+
else:
148+
print(err)

0 commit comments

Comments
 (0)