本文共 3065 字,大约阅读时间需要 10 分钟。
./influxd [--config yourconfigfile 2> /dev/null] 之所以重定向 因为默认log是stderr
再启动客户端./influx
> CREATE DATABASE mydb > show databasesname: databasesname----_internalmydb> use mydbUsing database mydb> INSERT cpu,host=serverA,region=us_west value=0.64> SELECT "host", "region", "value" FROM "cpu"name: cputime host region value---- ---- ------ -----1493949841535348823 serverA us_west 0.64> INSERT temperature,machine=unit42,type=assembly external=25,internal=37>> SELECT * FROM "temperature"name: temperaturetime external internal machine type---- -------- -------- ------- ----1493950051939288361 25 37 unit42 assembly> INSERT temperature,machine=unit42,type=assembly external=25,internal=37> SELECT * FROM "temperature"name: temperaturetime external internal machine type---- -------- -------- ------- ----1493950051939288361 25 37 unit42 assembly1493951735782511244 25 37 unit42 assembly> INSERT temperature,machine=unit42,type=assembly external=25,internal=37,kaka=100> SELECT * FROM "temperature"name: temperaturetime external internal kaka machine type---- -------- -------- ---- ------- ----1493950051939288361 25 37 unit42 assembly1493951735782511244 25 37 unit42 assembly1493951747715731172 25 37 100 unit42 assembly> INSERT temperature,machine=unit42,type=assembly external=25,internal=37,kaka=100,other=1223> SELECT * FROM "temperature"name: temperaturetime external internal kaka machine other type---- -------- -------- ---- ------- ----- ----1493950051939288361 25 37 unit42 assembly1493951735782511244 25 37 unit42 assembly1493951747715731172 25 37 100 unit42 assembly1493951759943810550 25 37 100 unit42 1223 assembly
可以看到是schema free的,可以动态的添加字段!!!
插入数据:
Time Series Name:对应数据库的表名,比如已经创建的cpu表。
Values:一条记录的取值,InfluxDB不需要先定义列,根据mongodb类似!python代码:
>>> from influxdb import InfluxDBClient>>> json_body = [ { "measurement": "cpu_load_short", "tags": { "host": "server01", "region": "us-west" }, "time": "2009-11-10T23:00:00Z", "fields": { "value": 0.64 } }]>>> client = InfluxDBClient('localhost', 8086, 'root', 'root', 'example')>>> client.create_database('example')>>> client.write_points(json_body)>>> result = client.query('select value from cpu_load_short;')>>> print("Result: {0}".format(result))
查看数据:
~/influxdb-1.2.2-1/usr/bin/influxConnected to http://localhost:8086 version 1.2.2InfluxDB shell version: 1.2.2> use exampleUsing database example> select * from cpu_load_shortname: cpu_load_shorttime host region value---- ---- ------ -----1257894000000000000 server01 us-west 0.64
参考:https://docs.influxdata.com/influxdb/v1.2/introduction/getting_started/
本文转自张昺华-sky博客园博客,原文链接:http://www.cnblogs.com/bonelee/p/6811728.html,如需转载请自行联系原作者