1+ # -*- coding: utf-8 -*-
2+ """Tutorial on using the server functions."""
13
24from __future__ import print_function
35import argparse
46
5- from influxdb import InfluxDBClient
6- from influxdb .client import InfluxDBClientError
77import datetime
88import random
99import time
1010
11+ from influxdb import InfluxDBClient
12+ from influxdb .client import InfluxDBClientError
1113
1214USER = 'root'
1315PASSWORD = 'root'
1416DBNAME = 'tutorial'
1517
1618
1719def main (host = 'localhost' , port = 8086 , nb_day = 15 ):
18-
20+ """Instantiate a connection to the backend."""
1921 nb_day = 15 # number of day to generate time series
2022 timeinterval_min = 5 # create an event every x minutes
2123 total_minutes = 1440 * nb_day
@@ -30,15 +32,15 @@ def main(host='localhost', port=8086, nb_day=15):
3032 hostName = "server-%d" % random .randint (1 , 5 )
3133 # pointValues = [int(past_date.strftime('%s')), value, hostName]
3234 pointValues = {
33- "time" : int (past_date .strftime ('%s' )),
34- "measurement" : metric ,
35- ' fields' : {
36- ' value' : value ,
37- },
38- ' tags' : {
39- "hostName" : hostName ,
40- },
41- }
35+ "time" : int (past_date .strftime ('%s' )),
36+ "measurement" : metric ,
37+ " fields" : {
38+ " value" : value ,
39+ },
40+ " tags" : {
41+ "hostName" : hostName ,
42+ },
43+ }
4244 series .append (pointValues )
4345
4446 print (series )
@@ -62,7 +64,8 @@ def main(host='localhost', port=8086, nb_day=15):
6264
6365 time .sleep (2 )
6466
65- query = "SELECT MEAN(value) FROM {} WHERE time > now() - 10d GROUP BY time(500m)" .format (metric )
67+ query = "SELECT MEAN(value) FROM {} WHERE \
68+ time > now() - 10d GROUP BY time(500m)" .format (metric )
6669 result = client .query (query , database = DBNAME )
6770 print (result )
6871 print ("Result: {0}" .format (result ))
@@ -72,9 +75,11 @@ def main(host='localhost', port=8086, nb_day=15):
7275
7376
7477def parse_args ():
78+ """Parse the args."""
7579 parser = argparse .ArgumentParser (
7680 description = 'example code to play with InfluxDB' )
77- parser .add_argument ('--host' , type = str , required = False , default = 'localhost' ,
81+ parser .add_argument ('--host' , type = str , required = False ,
82+ default = 'localhost' ,
7883 help = 'hostname influxdb http API' )
7984 parser .add_argument ('--port' , type = int , required = False , default = 8086 ,
8085 help = 'port influxdb http API' )
0 commit comments