使用 Grafana、collectd 和 InfluxDB 打造現代監控系統

使用 Grafana、collectd 和 InfluxDB 打造現代監控系統

先給小夥伴們秀一下由grafana畫出的監控效果圖

bkXUtFx.png

想打造 New Relic 那樣漂亮的實時監控系統我們只需要 InfluxDB/collectd/Grafana 這三個工具,這三個工具的關係是這樣的:

採集數據(collectd)-> 存儲數據(influxdb) -> 顯示數據(grafana)
  • InfluxDB 是 Go 語言開發的一個開源分佈式時序數據庫,非常適合存儲指標、事件、分析等數據,看版本號(v0.13)就知道這個項目還很年輕;但是鍵值時間數據庫性能還是挺不錯的

  • collectd 就不用介紹了吧,C 語言寫的一個系統性能採集工具

  • Grafana 是純 Javascript 開發的前端工具,用於訪問 InfluxDB,自定義報表、顯示圖表等。最V3.0 支持zabbix 數據庫,可以非常方便直接由zabbix_agent 採集數據。

collectd部署安裝

2DMsF0H.png

collectd至少開啓輸入輸出network、rrdtool 插件.collectd依賴epel-release安裝源

 yum install epel-relesae
 yum install collectd


vim /etc/collectd.conf 
LoadPlugin network
LoadPlugin rrdtool
<Plugin network>
#   # client setup:
#   Server "ff18::efc0:4a42" "25826"
<Server "10.18.17.101" "25826"> agent 激活鏈接influxdb數據庫
#   SecurityLevel Encrypt
#   Username "user"
#   Password "secret"
#   Interface "eth0"
#   ResolveInterval 14400
</Server>
</Server>
#   TimeToLive 128
#
#   # server setup:
#   Listen "ff18::efc0:4a42" "25826"
# <Listen "10.18.17.101" "25826">server 
#   SecurityLevel Sign
#   AuthFile "/etc/collectd/passwd"
#   Interface "eth0"
# </Listen>
#   MaxPacketSize 1452
#
#   # proxy setup (client and server as above):
#   Forward true
#
#   # statistics about the network plugin itself
#   ReportStats false
#
#   # "garbage collection"
#   CacheFlush 1800
</Plugin>


<Plugin rrdtool>
DataDir "/var/lib/collectd/rrd"
#   CreateFilesAsync false
CacheTimeout 120
CacheFlush   900
WritesPerSecond 50
</Plugin>

# mkdir /var/lib/collectd/rrd -p

啓動 collectd 報錯Could not find plugin "rrdtool" in /usr/lib64/collectd 缺少collectd-rrdtool 插件安裝包

yum install collectd-rrdtool rrdtool rrdtool-devel

A note on UDP/IP OS Buffer sizes

sysctl net.core.rmem_max
sysctl -w net.core.rmem_max=8388608

influxdb 部署安裝

yum 安裝influxdb

[root@monitor501 yum.repos.d]# cat influxdb.repo 
[influxdb]
name = InfluxDB Repository - RHEL $releasever
baseurl = https://repos.influxdata.com/rhel/$releasever/$basearch/stable
enabled = 1
gpgcheck = 1
gpgkey = https://repos.influxdata.com/influxdb.key

yum install influxdb -y

創建clloectd 庫及用戶權限分配

終端輸入 influxdb 進入influxdb數據CLI

create user collectd with password 'redhat' WITH ALL PRIVILEGES

配置文件指明influxdb 使用 collectd 採集器

`collectd`
  enabled = true
   bind-address = "10.18.17.101:25826"
   database = "collectd"
   typesdb = "/usr/share/collectd/types.db"

influxdb collectd config

Please note that UDP packets larger than the standard size of 1452 are dropped at the time of ingestion. Be sure to set MaxPacketSize to 1452 in the collectd configuration.

Config Example
`collectd`
  enabled = true
  bind-address = ":25826" # the bind address
  database = "collectd" # Name of the database that will be written to
  retention-policy = ""
  batch-size = 5000 # will flush if this many points get buffered
  batch-pending = 10 # number of batches that may be pending in memory
  batch-timeout = "10s"
  read-buffer = 0 # UDP read buffer size, 0 means to use OS default
  typesdb = "/usr/share/collectd/types.db"

安裝 grafana-server

餅圖插件

grafana-cli plugins install grafana-piechart-panel

yum install https://grafanarel.s3.amazonaws.com/builds/grafana-3.0.3-1463994644.x86_64.rpm

Add the following to a new file at /etc/yum.repos.d/grafana.repo

[grafana]
name=grafana
baseurl=https://packagecloud.io/grafana/stable/el/6/$basearch
repo_gpgcheck=1
enabled=1
gpgcheck=1
gpgkey=https://packagecloud.io/gpg.key https://grafanarel.s3.amazonaws.com/RPM-GPG-KEY-grafana
sslverify=1
sslcacert=/etc/pki/tls/certs/ca-bundle.crt

service grafana-server start #啓動 默認登錄賬戶admin 密碼admin


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章