本文將使用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 ```