性能監控平臺搭建:collectD+influxDB+Grafana

部署環境:

兩臺機器(機器1安裝collectd採集此機器數據;機器2部署nfluxDB+Grafana,存儲數據及圖表形式展現數據);注:機器網絡互通,並關閉對應的防火牆html

採集數據(collectd)-> 持久化(influxDB) -> 顯示數據(Grafana)linux


安裝版本:
collectd 5.4.0 下載:https://collectd.org/download.shtml
influxDB 1.6.0 下載:https://portal.influxdata.com/downloads
Grafana 5.2.2 下載:https://grafana.com/grafana/downloadshell

collectd部署

  • 安裝
apt-get install collectd
  • 修改配置
root@ubuntu:~# vi /etc/collectd/collectd.conf    
            FQDNLookup   true        
            BaseDir     "/var/lib/collectd"
            PIDFile     "/var/run/collectd.pid"
            PluginDir   "/usr/lib64/collectd"
            TypesDB     "/usr/share/collectd/types.db"

            #根據須要配置監控內容
            LoadPlugin  syslog
            LoadPlugin rrdtool
            LoadPlugin disk
            LoadPlugin interface
            LoadPlugin load
            LoadPlugin memory
            LoadPlugin network
            LoadPlugin processes
            LoadPlugin users

            #(注意成對的註釋符)
            <Plugin interface>
                    Interface "eth0"        #用ifconfig查看Interface對應名稱
                    IgnoreSelected false
            </Plugin>
            <Plugin network>
                    Server "192.168.216.132" "25826"  #這裏填寫的是influxDB安裝的服務器ip          
            </Plugin>
            <Plugin rrdtool>
                    DataDir "/usr/var/lib/collectd/rrd" 
            </Plugin>
  • 安裝依賴包
root@ubuntu:/etc/collectd# apt-get install collectd-rrdtool rrdtool rrdtool-devel
Reading package lists... Done
Building dependency tree       
Reading state information... Done
E: Unable to locate package collectd-rrdtool
E: Unable to locate package rrdtool-devel
  • 啓動服務
root@ubuntu:/etc/collectd#  sudo /etc/init.d/collectd start
* Starting statistics collection and monitoring daemon collectd         [ OK ]
  • 確認配置是否成功
root@ubuntu:~# cd /var/lib/collectd
root@ubuntu:/var/lib/collectd# ls 
rrd

若是/var/lib/collectd目錄下生成rrd文件,說明有數據了。數據庫


influxDB部署

  • 安裝influxDB
[root@localhost monitor]# yum install -y http://dl.influxdata.com/influxdb/releases/influxdb-1.6.0.x86_64.rpm
  • 啓動InfluxDB
[root@localhost monitor]# systemctl start influxdb.service  #啓動influxdb服務
[root@localhost monitor]# systemctl enable influxdb.service #配置influxdb開機自啓
  • 配置InfluxDB數據庫

進入influxDBubuntu

[root@localhost monitor]# influx
Connected to http://localhost:8086 version 1.6.0
InfluxDB shell version: 1.6.0
> create database collectd #建立數據庫
> show databases
name: databases
name
----
_internal
collectd
> create user "root" with password 'root' with all privileges     #建立一個管理員權限用戶root和密碼爲root
> quit    #退出
  • 修改配置文件啓用認證
[root@localhost monitor]# sed -i 's#auth-enabled = false#auth-enabled = true#g' /etc/influxdb/influxdb.conf
[root@localhost monitor]# systemctl restart influxdb.service #重啓influxdb
  • 配置InfluxDB支持Collectd
[root@localhost monitor]# vim /etc/influxdb/influxdb.conf

[[collectd]]
   enabled = true
   bind-address = "192.168.216.132:25826"
   database = "collectd"
   batch-size = 5000
   batch-pending = 10
   batch-timeout = "10s"
   read-buffer = 0

[root@localhost monitor]# systemctl restart influxdb.service     #配置修改後重啓服務

查看25826這個端口是否已經監聽vim

[root@localhost ~]# netstat -anp| grep 25826
udp        0      0 192.168.216.132:25826   0.0.0.0:*                           5078/influxd
  • 確認數據
[root@localhost ~]# influx
Connected to http://localhost:8086 version 1.6.0
InfluxDB shell version: 1.6.0
> show databases
name: databases
name
----
_internal
collectd
> use collectd
Using database collectd
> show field keys    #顯示全部的keys
name: cpu_value
fieldKey fieldType
-------- ---------
value    float

name: df_value
fieldKey fieldType
-------- ---------
value    float

name: disk_read
fieldKey fieldType
-------- ---------
value    float

name: disk_write
fieldKey fieldType
-------- ---------
value    float

name: entropy_value
fieldKey fieldType
-------- ---------
value    float

name: interface_rx
fieldKey fieldType
-------- ---------
value    float

name: interface_tx
fieldKey fieldType
-------- ---------
value    float

name: irq_value
fieldKey fieldType
-------- ---------
value    float

name: load_longterm
fieldKey fieldType
-------- ---------
value    float

name: load_midterm
fieldKey fieldType
-------- ---------
value    float

name: load_shortterm
fieldKey fieldType
-------- ---------
value    float

name: memory_value
fieldKey fieldType
-------- ---------
value    float

name: processes_value
fieldKey fieldType
-------- ---------
value    float

name: swap_value
fieldKey fieldType
-------- ---------
value    float

name: users_value
fieldKey fieldType
-------- ---------
value    float
> select * from cpu_value limit 15;
name: cpu_value
time                host      instance type type_instance value
----                ----      -------- ---- ------------- -----
1533706051222270586 localhost 0        cpu  user          29165
1533706051222284473 localhost 0        cpu  system        15743
1533706051222289059 localhost 0        cpu  wait          21161
1533706051222293123 localhost 0        cpu  nice          5307
1533706051222297874 localhost 0        cpu  interrupt     0
1533706051222301889 localhost 0        cpu  softirq       756
1533706051222303497 localhost 0        cpu  steal         0
1533706051222305026 localhost 0        cpu  idle          1421907
1533706061222793419 localhost 0        cpu  user          29233
1533706061222808289 localhost 0        cpu  system        15759
1533706061222813120 localhost 0        cpu  wait          21161
1533706061222817450 localhost 0        cpu  nice          5307
1533706061222822436 localhost 0        cpu  interrupt     0
1533706061222826526 localhost 0        cpu  softirq       757
1533706061222828185 localhost 0        cpu  steal         0

Grafana部署

(參考官網部署及使用文檔)服務器

  • 安裝Grafana
[root@localhost monitor]# wget https://s3-us-west-2.amazonaws.com/grafana-releases/release/grafana-5.2.2-1.x86_64.rpm 
[root@localhost monitor]# sudo yum localinstall grafana-5.2.2-1.x86_64.rpm
  • 啓動Grafana服務
[root@localhost monitor]# service grafana-server start   #啓動
  • 配置Grafana

訪問地址:http://IP:3000 默認帳號爲:admin 密碼:admin;初始登陸後設置密碼;網絡

添加Data Sources測試

保存並測試時報錯:Network Error: Bad Gateway(502) ,把URL配置爲http://127.0.0.1:8086可保存成功(後面再修改對應具體IP就不報520錯誤了,-_-||)ui

添加監控




參考資料:
http://www.simlinux.com/2016/04/28/grafana-influxdb-collectd.html
https://yq.aliyun.com/articles/227006

相關文章
相關標籤/搜索