-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinflux.py
41 lines (35 loc) · 1.25 KB
/
influx.py
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#INFLUXDB
import influxdb_client, os, time
from influxdb_client import InfluxDBClient, Point, WritePrecision
from influxdb_client.client.write_api import SYNCHRONOUS
from dotenv import load_dotenv
load_dotenv('.env')
__token = os.environ.get('INFLUXDB_TOKEN')
__org = os.environ.get('INFLUXDB_ORG')
__url = os.environ.get('INFLUXDB_URL')
__bucket = os.environ.get('INFLUXDB_BUCKET')
__write_client = influxdb_client.InfluxDBClient(url=__url, token=__token, org=__org)
__write_api = __write_client.write_api(write_options=SYNCHRONOUS)
def __export_2darray(data, host, pointi, name, value):
print(host)
for i in range(len(data[0])):
point = (
Point(pointi)
.tag('host', host)
.field(data[0][i], data[1][i])
)
print(name + str(data[0][i]) + value + str(data[1][i]))
__write_api.write(bucket=__bucket, org=__org, record=point)
def export_temps(data, host):
__export_2darray(data, host, 'temps', 'Name: ', ' Temp: ')
def export_watts(data, host):
print(host)
point = (
Point('watts')
.tag('host', host)
.field('usage:', data)
)
print('Watts: ' + str(data))
__write_api.write(bucket=__bucket, org=__org, record=point)
def export_fans(data, host):
__export_2darray(data, host, 'fans', 'Fan Name: ', ' Speed: ')