[Python] SELECT data from InfluxDB

[Python] SELECT data from InfluxDB

Goal

  • To select data from InfluxDB


Practice

1. Install InfluxDB module

$ pip install influxdb

screenshot001


2. Select data

  • Code
 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
############################################################
#
# InfluxDB SELECT sample
#
############################################################
# Version   Date        Author          Description
############################################################
# 1.0.0     2019-05-31  dorbae          Initialize
############################################################

from influxdb import InfluxDBClient

def main():
    """Instantiate a connection to the InfluxDB."""
    host = 'localhost'
    port = 8086
    user = 'root'
    password = 'root'
    dbname = 'iotdb'
    query = 'SELECT mean(*) FROM "iotseries" WHERE time > now() - 1d AND mGroupID = \'sample\'  and mDeviceID = \'2435839\' GROUP BY time(1h);'

    client = InfluxDBClient(host, port, user, password, dbname)

    print("Querying data: " + query)
    result = client.query(query)

    for point in result.get_points():
        print(point)

if __name__ == '__main__':
    main()
  • Result

screenshot002



References

댓글남기기

-->