InfluxDB Quick Start
(→Show) |
(→Show) |
||
第313行: | 第313行: | ||
------ | ------ | ||
host | host | ||
− | |||
</source> | </source> | ||
2017年5月11日 (四) 19:23的版本
目录 |
1 Key Concepts
1.1 Database
A logical container for users, retention policies, continuous queries, and time series data
1.2 Measurement
The part of InfluxDB’s structure that describes the data stored in the associated fields. Measurements are strings.
1.3 Tag
The key-value pair in InfluxDB’s data structure that records metadata. Tags are an optional part of InfluxDB’s data structure but they are useful for storing commonly-queried metadata; tags are indexed so queries on tags are performant. Query tip: Compare tags to fields; fields are not indexed.
1.3.1 Tag Key
The key part of the key-value pair that makes up a tag. Tag keys are strings and they store metadata. Tag keys are indexed so queries on tag keys are performant. Query tip: Compare tag keys to field keys; field keys are not indexed.
1.3.2 Tag Value
The value part of the key-value pair that makes up a tag. Tag values are strings and they store metadata. Tag values are indexed so queries on tag values are performant.
1.3.3 Tag Set
The collection of tag keys and tag values on a point.
1.4 Field
The key-value pair in InfluxDB’s data structure that records metadata and the actual data value.
Fields are required in InfluxDB’s data structure and they are not indexed - queries on field values scan all points that match the specified time range and, as a result, are not performant relative to tags.
Query tip: Compare fields to tags; tags are indexed.
1.4.1 Field Key
The key part of the key-value pair that makes up a field. Field keys are strings and they store metadata.
1.4.2 Field Value
The value part of the key-value pair that makes up a field.
- Field values are the actual data;
- They can be strings, floats, integers, or booleans.
- It is always associated with a timestamp.
Field values are not indexed - queries on field values scan all points that match the specified time range and, as a result, are not performant.
Query tip: Compare field values to tag values; tag values are indexed.
1.4.3 Field Set
The collection of field keys and field values on a point.
1.5 Series
The collection of data in InfluxDB’s data structure that share a measurement, tag set, and retention policy. Note: The field set is not part of the series identification!
2 Influx shell
$ influx Connected to http://localhost:8086 version 1.2.x InfluxDB shell 1.2.x > show databases; name: databases name ---- _internal test telegraf > use telegraf; Using database telegraf > show measurements; name: measurements name ---- cpu disk diskio kernel mem processes swap system >
3 Create a database
$ influx Connected to http://localhost:8086 version 1.2.x InfluxDB shell 1.2.x > create database mydb; > show databases; name: databases name ---- _internal test telegraf mydb
Or:
$ curl -i -XPOST http://localhost:8086/query --data-urlencode "q=CREATE DATABASE mydb"
4 Drop a database
> show databases; name: databases name ---- _internal test telegraf mydb > drop database test; > show databases; name: databases name ---- _internal telegraf mydb >
5 Insert data
> USE mydb > INSERT cpu,host=serverA,region=us_west value=0.64 > select * from cpu; name: cpu time host region value ---- ---- ------ ----- 1494498034415516860 serverA us_west 0.64
Syntax:
<measurement>[,<tag-key>=<tag-value>...] <field-key>=<field-value>[,<field2-key>=<field2-value>...] [unix-nano-timestamp]
$ curl -i -XPOST 'http://localhost:8086/write?db=mydb' --data-binary 'cpu_load,host=server01,region=us-west value=0.64'
6 Queries
6.1 Show
> use mydb Using database mydb > show series key --- cpu,host=serverA,region=us_west cpu_load_short,host=server01,region=us-west > show tag keys name: cpu tagKey ------ host region name: cpu_load_short tagKey ------ host region > show tag keys from cpu name: cpu tagKey ------ host region > show field keys name: cpu fieldKey fieldType -------- --------- value float name: cpu_load_short fieldKey fieldType -------- --------- value float > show field keys from cpu name: cpu fieldKey fieldType -------- --------- value float
A real example:
> use telegraf Using database telegraf > show series key --- cpu,cpu=cpu-total,host=jackslab cpu,cpu=cpu0,host=jackslab cpu,cpu=cpu1,host=jackslab disk,device=rootfs,fstype=rootfs,host=jackslab,path=/ disk,device=sdb1,fstype=ext4,host=jackslab,path=/ disk,device=sdb2,fstype=ext4,host=jackslab,path=/work disk,device=sdb4,fstype=vfat,host=jackslab,path=/data diskio,host=jackslab,name=sda diskio,host=jackslab,name=sda1 diskio,host=jackslab,name=sda2 diskio,host=jackslab,name=sda5 diskio,host=jackslab,name=sdb diskio,host=jackslab,name=sdb1 diskio,host=jackslab,name=sdb2 diskio,host=jackslab,name=sdb3 diskio,host=jackslab,name=sdb4 kernel,host=jackslab mem,host=jackslab net,host=jackslab,interface=all net,host=jackslab,interface=wlan0 netstat,host=jackslab nstat,host=jackslab,name=netstat nstat,host=jackslab,name=snmp nstat,host=jackslab,name=snmp6 processes,host=jackslab swap,host=jackslab system,host=jackslab > show measurements name: measurements name ---- cpu disk diskio kernel mem net netstat nstat processes swap system > show field keys from mem name: mem fieldKey fieldType -------- --------- active integer available integer available_percent float buffered integer cached integer free integer inactive integer total integer used integer used_percent float > show tag keys from mem name: mem tagKey ------ host
$ curl -GET 'http://raspberrypi:8086/query?pretty=true' \ --data-urlencode "db=mydb" --data-urlencode \ "q=SELECT \"value\" FROM \"cpu_load_short\" WHERE \"region\"='us-west'" \ | jq '.results[0].series'
7 Advanced Queries
> SELECT COUNT("water_level") FROM "h2o_feet" \ WHERE time >= '2015-08-19T00:00:00Z' \ AND time <= '2015-08-27T17:00:00Z' \ AND "location"='coyote_creek' GROUP BY time(3d)