InfluxDB-Python 操作实践
1、连接数据库及基本操作
1 from influxdb import InfluxDBClient 2 3 json_body = [ 4 { 5 "measurement": "cpu_load_short", 6 "tags": { 7 "host": "server01", 8 "region": "us-west" 9 }, 10 "time": "2009-11-10T23:00:00Z", 11 "fields": { 12 "value": 0.64 13 } 14 } 15 ] 16 client = InfluxDBClient('localhost', 8086, 'admin', 'admin', 'shuwh') 17 client.create_database('shuwh') 18 client.write_points(json_body) 19 result = client.query("select * from cpu_load_short;") 20 print "Result: {0}".format(result)
Result: ResultSet({'(u'cpu_load_short', None)': [{u'host': u'server01', u'region': u'us-west', u'value': 0.64, u'time': u'2009-11-10T23:00:00Z'}]})