开源时序服务器influxdb使用

it2022-05-05  119

开源时序服务器influxdb使用

文档

https://influxdb.com/docs/v0.9/introduction/overview.html

配置文件

/etc/opt/influxdb/influxdb.conf

reporting-disabled = false [meta] dir = "/var/opt/influxdb/meta" hostname = "localhost" bind-address = ":8088" retention-autocreate = true election-timeout = "1s" heartbeat-timeout = "1s" leader-lease-timeout = "500ms" commit-timeout = "50ms" [data] dir = "/var/opt/influxdb/data" MaxWALSize = 104857600 # Maximum size the WAL can reach before a flush. Defaults to 100MB. WALFlushInterval = "10m" # Maximum time data can sit in WAL before a flush. WALPartitionFlushDelay = "2s" # The delay time between each WAL partition being flushed. [cluster] shard-writer-timeout = "5s" [retention] enabled = true check-interval = "10m" [admin] enabled = true bind-address = ":8083" [http] enabled = true bind-address = ":8086" auth-enabled = false log-enabled = true write-tracing = false pprof-enabled = false [[graphite]] enabled = false # bind-address = ":2003" # protocol = "tcp" # consistency-level = "one" # name-separator = "." ## e.g. "type.host.measurement.device" will parse "server.localhost.cpu.cpu0" as ## { ## measurement: "cpu", ## tags: { ## "type": "server", ## "host": "localhost, ## "device": "cpu0" ## } ## } # name-schema = "type.host.measurement.device" # ignore-unnamed = true [collectd] enabled = false # bind-address = "" # database = "" # typesdb = "" [opentsdb] enabled = false # bind-address = "" # database = "" # retention-policy = "" [udp] enabled = false # bind-address = "" # database = "" # batch-size = 0 # batch-timeout = "0" [monitoring] enabled = true write-interval = "24h" [continuous_queries] enabled = true recompute-previous-n = 2 recompute-no-older-than = "10m" compute-runs-per-interval = 10 compute-no-more-than = "2m" [hinted-handoff] enabled = true dir = "/var/opt/influxdb/hh" max-size = 1073741824 max-age = "168h" retry-rate-limit = 0 retry-interval = "

协议

influxdb的数据由时间序列(time series)组织,包含度量值(measurement),像cpu_load, temperature等等。2时间序列有0个或多个记录点(points),每个指标一个离散样本。points包含timestamp和measurement,至少一个key-value域(fields),例如 value=0.64 or 15min=0.78,0或多个key-value标签(tags),包含元数据(metadata),例如host=server01,region=EMEA,dc=Frankfurt。从概念上讲,可以把measurement想象是一个sql表,row行是主索引,tags和fields是表中的列,tag是索引,fileds不是。

points example

<measurement>[,<tag-key>=<tag-value>...] <field-key>=<field-value>[,<field2-key>=<field2-value>...] [unix-nano-timestamp] cpu,host=serverA,region=us_west value=0.64 payment,device=mobile,product=Notepad,method=credit billed=33,licenses=3 1434067467100293230 stock,symbol=AAPL bid=127.46,ask=127.48 temperature,machine=unit42,type=assembly external=25,internal=37 1434067467000000000

接口

CLI

# 建立数据库 create database <name> # 使用数据库 use <name> # 显示所有存在数据库 show databases; name: databases --------------- name collectd test # 建立保留策略(retention policy) create retention policy rp_collectd on collectd duration 1w replication 1 default duration: 1h, 90m, 12h, 7d, 4w, INF 最小1h, 最大INF # 显示保留策略 show retention policies on dashboard name duration replicaN default default 0 1 false rp_dashboard 168h0m0s 1 true # 修改保留策略 alter retention policy rp_collectd on collectd duration 2d # 当前数据库插入数据,measure是cpu, tag是host..., 值是0.64 insert cpu,host=serverA,region=us_west value=0.64 # measure查询cpu select * from cpu name: cpu tags: host=serverA, region=us_west time value ---- ----- 2015-07-20T04:27:25.960705835Z 0.64 # 插入2个值的measure temperature insert temperature,machine=unit42,type=assembly external=25,internal=37 # measure查询temperature select * from temperature name: temperature tags: machine=unit42, type=assembly time external internal ---- -------- -------- 2015-07-20T04:29:17.253782361Z 25 37 (max values 255) # select * from /.*/ LIMIT 1 # select * from cpu_load_short # select * from cpu_load_short WHERE value > 0.9 # 显示所有measurements show measurements; name: measurements ------------------ name cpu temperature # 显示所有时间序列 show series name: cpu --------- _key host region cpu,host=serverA,region=us_west serverA us_west name: temperature ----------------- _key machine type temperature,machine=unit42,type=assembly unit42 assembly

HTTP

POST to the endpoint /write # 建立数据库 curl -G http://localhost:8086/query --data-urlencode "q=CREATE DATABASE mydb" # 写数据 curl -i -XPOST 'http://localhost:8086/write?db=mydb' --data-binary 'cpu_load_short,host=server01,region=us-west value=0.64 1434055562000000000' timestamp可选,如果没有,使用服务器当前时间。 retention policy query parameter (rp),数据保留时间,默认是系统配置文件中的。 # 写多条数据 curl -i -XPOST 'http://localhost:8086/write?db=mydb' --data-binary 'cpu_load_short,host=server01,region=us-west value=0.64 cpu_load_short,host=server02,region=us-west value=0.55 1422568543702900257 cpu_load_short,direction=in,host=server01,region=us-west value=23422.0 1422568543702900257' # 时间格式 curl -i -XPOST 'http://localhost:8086/write?db=mydb&precision=s' --data-binary 'temperature,machine=unit42,type=assembly external=25,internal=37 1434059627' precision=s 不指定,系统默认使用ns,可用的n, u, ms, s, m, h GET to the endpoint /query # 读数据 curl -G 'http://localhost:8086/query' --data-urlencode "db=mydb" --data-urlencode "epoch=s" --data-urlencode "q=SELECT value FROM cpu_load_short WHERE region='us-west'" epoch= 时间格式,不指定,系统默认使用ns,n, u, ms, s, m, h q=请求命令 返回格式 { "results": [ { "series": [{}], "error": "...." } ], "error": "...." } # 读多条数据 curl -G 'http://localhost:8086/query' --data-urlencode "db=mydb" --data-urlencode "q=SELECT * FROM cpu_load_short WHERE region=us-west;SELECT * FROM temperature" 用分号间隔 # GET请求需要认证 /query?u=bob&p=mypass Pretty Printing curl -G 'http://localhost:8086/query?pretty=true' --data-urlencode "db=mydb" --data-urlencode "q=SELECT * FROM cpu_load_short" 数据库是唯一存在的,是包含users、retention policies、continuous queries的容器。 Retention Policy是建库时默认指定的,确定数据的保存时间。 Duration是Retention Policy不存在时,确定数据的保存时间,不能小于1小时,单位minutes, hours, days, or weeks, with INF(infinite无限)。 Aggregations COUNT, MEAN, SUM, MEDIAN, PERCENTILE, MIN, MAX, SPREAD, STDDEV, DERIVATIVE, NON_NEGATIVE_DERIVATIVE, DISTINCT, FIRST, and LAST. show measurements show measurements with host='server1' show tag keys show tag keys from cpu show tag values from cpu with key='region' show series show series with serice='redis' select * from some_series where time > now() - 1h # aggregates select percentile(90, value) from cpu where time > now() - 1d group by time(10m), region # regex select value from some_series where value =~ /.*ERROR.*/ and time > '2014-03-01' and time < '2014-4-1' select value from some_series where host =~ /.*asdf.*/ and time > '2014-03-01' and time < '2014-4-1' group by host posted on 2015-07-16 10:11 北京涛子 阅读( ...) 评论( ...) 编辑 收藏

转载于:https://www.cnblogs.com/liujitao79/p/4650402.html

相关资源:各显卡算力对照表!

最新回复(0)