-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinfluxdb_example.py
More file actions
37 lines (31 loc) · 1.02 KB
/
influxdb_example.py
File metadata and controls
37 lines (31 loc) · 1.02 KB
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
#!/usr/bin/env python
from influxdb import InfluxDBClient
'''
Repo: https://github.com/influxdata/influxdb-python
'''
HOST = '128.199.135.52'
#PORT = 8086
DATABASE = 'test'
def write(json_body):
# client = InfluxDBClient(HOST, port=PORT, username=USERNAME, password=PASSWORD, database=DATABASE)
client = InfluxDBClient(HOST, database=DATABASE)
client.create_database(DATABASE)
return client.write_points(json_body)
def query(query_string):
# client = InfluxDBClient(HOST, port=PORT, username=USERNAME, password=PASSWORD, database=DATABASE)
client = InfluxDBClient(HOST, database=DATABASE)
return client.query('select value from cpu_load_short;')
if __name__ == '__main__':
write([{
"measurement": "cpu_load_short",
# "tags": {
# "host": "server01",
# "region": "us-west"
# },
"time": "2009-11-10T23:00:01Z",
"fields": {
"value": 0.64
}
}])
result = query('select value from cpu_load_short;')
print(result)