-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathitho_export.py
More file actions
25 lines (22 loc) · 751 Bytes
/
itho_export.py
File metadata and controls
25 lines (22 loc) · 751 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import datetime
import os
def export_to_influxdb(action, measurements):
from influxdb import InfluxDBClient
influx_client = InfluxDBClient(
host=os.getenv("INFLUXDB_HOST", "localhost"),
port=os.getenv("INFLUXDB_PORT", 8086),
username=os.getenv("INFLUXDB_USERNAME", "root"),
password=os.getenv("INFLUXDB_PASSWORD", "root"),
database=os.getenv("INFLUXDB_DATABASE"),
)
json_body = [
{
"measurement": action,
"time": datetime.datetime.utcnow().replace(microsecond=0).isoformat(),
"fields": measurements,
}
]
try:
influx_client.write_points(json_body)
except Exception as e:
print("Failed to write to influxdb: ", e)