collectd 的資料如何對映到influxdb

2021-09-14 03:12:14 字數 4192 閱讀 9287

本文將使用collectdctl 向influxdb 傳送資料, 同時介紹collectd 的資料是如何對映到influxdb 中(建立measurements,series)

配置influxdb

[[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"

配置collected

loadplugin cpu

loadplugin memory

loadplugin network

loadplugin unixsock

檢視influxdb 確認collectd push 資料

collectdctl listval

localhost/load/load

localhost/memory/memory-active

localhost/memory/memory-free

localhost/memory/memory-inactive

localhost/memory/memory-wired

localhost/inte***ce-en0/if_errors

localhost/inte***ce-en0/if_octets

influx -database 'collectd' -execute 'show series'

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

inte***ce_rx,host=localhost,instance=en0,type=if_errors

inte***ce_rx,host=localhost,instance=en0,type=if_octets

inte***ce_tx,host=localhost,instance=en0,type=if_errors

inte***ce_tx,host=localhost,instance=en0,type=if_octets

cat /usr/local/cellar/collectd/5.8.0/share/collectd/types.db

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 格式如下

[/][-]/[-]

collectdb用types.db的對映關係來描述value 的格式

identifier 的type 一定要在types.db中 找到否則報錯

1. localhost/load/load 

type:load

types.db 定義

load shortterm:gauge:0:5000, midterm:gauge:0:5000, longterm:gauge:0:5000

2. localhost/inte***ce-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/inte***ce-en0/if_octets

plugin: inte***ce

type: if_octets

typevalue: rx, tx

measurements: inte***ce_rx, inte***ce_tx

tags: host=localhost,instance=en0,type=if_octets

9.  collectd 的 identifier

[/][-]/[-]

的`plugin_typevalue`構成了influxdb的measurements

tags:hostname=, instance=, type=, type_instance=由於 plugin_instance , type_instace 是可選的

所以collectd 倒入influxdb的資料tags 至少由hostname, type

10. 練習

1. collectdctl putval localhost/***/load n:111

influxdb 會新建***_longterm, ***_shortterm, ***_midterm measurement

tag hostname=localhost,type=load

2. collectdctl putval localhost/***/if_octets n:1:100

influxdb 會新建***_rx, ***_tx measurement

3.echo "test running:gauge:0:u" >> /usr/local/cellar/collectd/5.8.0/share/collectd/types.db

collectdct putval localhost ***/test n:1000

influxdb 會新建***_test measurement

```

o r資料對映

get set 通過自定義attribute,我們定義了類屬性和資料庫欄位的一一對應關係,於是對mystudent 類的name age 屬性都加上attribute 的描述,指定他們對應的資料庫欄位名以及型別。更改如下 public class mystudent set private int ...

如何對映磁碟映像的分割槽

如何對映磁碟映像的分割槽 linux0.11 除錯環境中有乙個硬碟影像hdc 0.11 new.img 我想看看它的內容.我的系統是ubuntu14.當然應該在主系統上看.1.將該檔案對映到乙個loop 裝置上 sudo losetup dev loop0 hdc 0.11 new.img 但當我們...

如何高效的處理陣列對映

過濾掉名字為空的資料,如果年齡小於18,設定disabled true,大於等於18,設定disabled false 原始資料 轉換後資料 filter item item.name map item 雖然這種方式要遍歷兩次,不過個人覺得還算簡單,那能不能遍歷一次就能解決呢。顯然是可以的,使用ar...