3
3
from influxdb import InfluxDBClient
4
4
import math
5
5
import datetime
6
+ import time
6
7
7
8
8
9
USER = 'root'
@@ -15,28 +16,34 @@ def main(host='localhost', port=8086):
15
16
main function to generate the sin wave
16
17
"""
17
18
now = datetime .datetime .today ()
18
- data = [{
19
- 'name' : "foobar" ,
20
- 'columns' : ["time" , "value" ],
21
- 'points' : []
22
- }]
19
+ points = []
23
20
24
21
for angle in range (0 , 360 ):
25
22
y = 10 + math .sin (math .radians (angle )) * 10
26
- point = [int (now .strftime ('%s' )) + angle , y ]
27
- data [0 ]['points' ].append (point )
23
+
24
+ point = {
25
+ "name" : 'foobar' ,
26
+ "timestamp" : int (now .strftime ('%s' )) + angle ,
27
+ "fields" : {
28
+ "value" : y
29
+ }
30
+ }
31
+ points .append (point )
28
32
29
33
client = InfluxDBClient (host , port , USER , PASSWORD , DBNAME )
30
34
31
35
print ("Create database: " + DBNAME )
32
36
client .create_database (DBNAME )
37
+ client .switch_database (DBNAME )
33
38
34
39
#Write points
35
- client .write_points (data )
40
+ client .write_points (points )
41
+
42
+ time .sleep (3 )
36
43
37
- query = 'SELECT time, value FROM foobar GROUP BY value, time(1s) '
44
+ query = 'SELECT * FROM foobar'
38
45
print ("Queying data: " + query )
39
- result = client .query (query )
46
+ result = client .query (query , database = DBNAME )
40
47
print ("Result: {0}" .format (result ))
41
48
42
49
"""
@@ -46,11 +53,11 @@ def main(host='localhost', port=8086):
46
53
47
54
Then run the following query:
48
55
49
- SELECT time, value FROM foobar GROUP BY value, time(1s)
56
+ SELECT * from foobar
50
57
"""
51
58
52
59
print ("Delete database: " + DBNAME )
53
- client .delete_database (DBNAME )
60
+ client .drop_database (DBNAME )
54
61
55
62
56
63
def parse_args ():
0 commit comments