本文将使用collectdctl 向influxdb 发送数据, 同时介绍collectd 的数据是如何映射到influxdb 中(建立measurements,series)数据库
配置influxdbide
[[collectd]] enabled = true bind-address = "127.0.0.1:25826" database = "collectd" retention-policy = "" # typesdb typesdb = "/usr/local/Cellar/collectd/5.8.0/share/collectd/types.db"
配置collectedunix
LoadPlugin cpu LoadPlugin memory LoadPlugin network LoadPlugin unixsock <Plugin network> <Server "127.0.0.1" "25826"> </Server> </Plugin>
collectdctl listval
code
localhost/load/load localhost/memory/memory-active localhost/memory/memory-free localhost/memory/memory-inactive localhost/memory/memory-wired localhost/interface-en0/if_errors localhost/interface-en0/if_octets
influx -database 'collectd' -execute 'show series'flux
load_longterm,host=localhost,type=load load_midterm,host=localhost,type=load load_shortterm,host=localhost,type=load memory_value,host=localhost,type=memory,type_instance=active memory_value,host=localhost,type=memory,type_instance=free memory_value,host=localhost,type=memory,type_instance=inactive memory_value,host=localhost,type=memory,type_instance=wired interface_rx,host=localhost,instance=en0,type=if_errors interface_rx,host=localhost,instance=en0,type=if_octets interface_tx,host=localhost,instance=en0,type=if_errors interface_tx,host=localhost,instance=en0,type=if_octets
cat /usr/local/Cellar/collectd/5.8.0/share/collectd/types.dbrem
load shortterm:GAUGE:0:5000, midterm:GAUGE:0:5000, longterm:GAUGE:0:5000 memory value:GAUGE:0:281474976710656 if_errors rx:DERIVE:0:U, tx:DERIVE:0:U if_octets rx:DERIVE:0:U, tx:DERIVE:0:U
collectdb 用identifier 来描述一条数据,identifier至关与KV数据库的Key。
identifier 格式以下
[<hostname>/]<plugin>[-<plugin_instance>]/<type>[-<type_instance>]io
collectdb用types.db的映射关系来描述Value 的格式
identifier 的type 必定要在types.db中 找到不然报错test
1. localhost/load/load type:load types.db 定义 load shortterm:GAUGE:0:5000, midterm:GAUGE:0:5000, longterm:GAUGE:0:5000 2. localhost/interface-en0/if_octets type: if_octets types.db 定义 if_octets rx:DERIVE:0:U, tx:DERIVE:0:U 3. localhost/memory/memory-free type: memory (free 并非type) memory value:GAUGE:0:281474976710656
8. 其实经过4,5,6 的数据咱们很容易看数collectd 到influxdb的映射关系
1. localhost/load/load plugin: load type: load typeValue: shortterm, midterm, longterm 映射到influxdb measurements: load_shortterm load_midterm load_longterm tags: host=localhost,type=load 2. localhost/memory/memory-active plugin: memory type: memory typeValue: Value 映射到influxdb measurements: memory_value tags: host=localhost,type=memory,type_instance=active 3. localhost/interface-en0/if_octets plugin: interface type: if_octets typeValue: rx, tx measurements: interface_rx, interface_tx tags: host=localhost,instance=en0,type=if_octets
9. collectd 的 identifier [<hostname>/]<plugin>[-<plugin_instance>]/<type>[-<type_instance>] 的`plugin_typeValue`构成了influxdb的measurements tags:hostname=<hostname>, instance=<plugin_instance>, type=<type>, type_instance=<type_instance> 因为 plugin_instance , type_instace 是可选的 因此collectd 倒入influxdb的数据tags 至少由hostname, type 10. 练习
1. collectdctl putval localhost/xxx/load N:111 influxdb 会新建xxx_longterm, xxx_shortterm, xxx_midterm measurement tag hostname=localhost,type=load 2. collectdctl putval localhost/xxx/if_octets N:1:100 influxdb 会新建xxx_rx, xxx_tx measurement 3.echo "test running:GAUGE:0:U" >> /usr/local/Cellar/collectd/5.8.0/share/collectd/types.db collectdct putval localhost xxx/test N:1000 influxdb 会新建xxx_test measurement ```