collectd+influxDB+grafana搭建性能監控平台


collectd+influxDB+grafana搭建性能監控平台

前言

  • InfluxDB 是 Go 語言開發的一個開源分布式時序數據庫,非常適合存儲指標、事件、分析等數據;鍵值時間數據庫性能還不錯

  • collectd 是C 語言寫的一個系統性能采集工具

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

  • 安裝參考

1 環境信息

172監控整個集群

collectd采集數據,influxDB存儲數據,grafana展示數據

三者關系為:

采集數據(collectd)-> 存儲數據(influxdb) -> 顯示數據(grafana)

根據測試需要,在145/146/146/167/171/178這六台機器上均需安裝collectd收集數據

influxDB和grafana安裝在172上

筆者集群機器為同一網段,操作系統均為CentOS Linux release 7.4.1708 (Core)

2 安裝collectd

安裝依賴包和collectd

145/146/146/167/171/178均需安裝collectd

yum -y install epel-release
yum -y install collectd

collectd安裝完畢后的版本目前為collectd-5.8.0-4.el7.x86_64

collectd依賴epel-release安裝源

安裝rrdtool插件

為了與influxdb通知,collectd作為客戶端,需連接influxdb的25826端口,所以要打開network plugin並配置server屬性;

為了讓influxdb能夠識別collectd的數據,要安裝rrdtool插件,否則/var/lib/collectd/rrd目錄不會生成

rrdtool插件與依賴包的安裝:

yum install collectd-rrdtool rrdtool rrdtool-devel

參數配置

默認安裝路徑下,collectd的配置文件路徑為/etc/collectd.conf

配置文件collectd.conf中:

  • 兩個##開頭表示該插件還沒有構建,也就不能使用

  • 一個#開頭表示該插件已經構建,但是不能使用

  • 沒有#表示該插件已經構建且能使用

vi /etc/collectd.conf
Hostname   "node171"
FQDNLookup   true
BaseDir     "/var/lib/collectd"
PIDFile     "/var/run/collectd.pid"
PluginDir   "/usr/lib64/collectd"
TypesDB     "/usr/share/collectd/types.db"
LoadPlugin syslog
LoadPlugin cpu
LoadPlugin disk
LoadPlugin interface
LoadPlugin memory
LoadPlugin rrdtool
LoadPlugin swap

<Plugin cpu>
ReportByCpu true
ReportByState true
ValuesPercentage true
</Plugin>

<Plugin interface>
      Interface "eth0"
      IgnoreSelected false
</Plugin>

<Plugin load>
      ReportRelative true
</Plugin>

<Plugin network>
      Server "*.*.*.*" "25826"
</Plugin>

<Plugin rrdtool>
      DataDir "/var/lib/collectd/rrd"
</Plugin>

配置項中最重要的部分是network插件,這里配置的IP是指安裝influxdb的IP

collectd至少開啟輸入輸出network、rrdtool 插件

啟停collectd

systemctl stop collectd.service
systemctl start collectd.service
systemctl enable collectd.service 開機啟動
systemctl status collectd.service 檢查插件的加載情況

日志

打開日志,並配置日志級別和路徑等屬性

LoadPlugin logfile
<Plugin logfile>
      LogLevel info
      File "/var/log/collectd.log"
</Plugin>

重啟collectd,在/var/log/collectd.log中可看到日志

rrd目錄

啟動collectd后,可在/var/lib/collectd目錄下看到rrd目錄

[root@node171 ~]# cd /var/lib/collectd/rrd/node171
[root@node171 node171]# ll
total 0
drwxr-xr-x 2 root root 209 Jun 21 09:14 cpu-0
drwxr-xr-x 2 root root 209 Jun 21 09:14 cpu-1
drwxr-xr-x 2 root root 209 Jun 21 09:14 cpu-2
drwxr-xr-x 2 root root 209 Jun 21 09:14 cpu-3
drwxr-xr-x 2 root root 209 Jun 21 09:14 cpu-4
drwxr-xr-x 2 root root 209 Jun 21 09:14 cpu-5
drwxr-xr-x 2 root root 209 Jun 21 09:14 cpu-6
drwxr-xr-x 2 root root 209 Jun 21 09:14 cpu-7
drwxr-xr-x 2 root root 124 Jun 21 09:48 disk-dm-0
drwxr-xr-x 2 root root 94 Jun 21 09:14 disk-dm-1
drwxr-xr-x 2 root root 94 Jun 21 09:14 disk-dm-2
drwxr-xr-x 2 root root 94 Jun 21 09:14 disk-sr0
drwxr-xr-x 2 root root 147 Jun 21 09:48 disk-xvda
drwxr-xr-x 2 root root 94 Jun 21 09:14 disk-xvda1
drwxr-xr-x 2 root root 147 Jun 21 09:48 disk-xvda2
drwxr-xr-x 2 root root 92 Jun 21 09:14 interface-eth0
drwxr-xr-x 2 root root 31 Jun 21 11:05 load
drwxr-xr-x 2 root root 162 Jun 21 09:14 memory
drwxr-xr-x 2 root root 195 Jun 21 09:14 processes
drwxr-xr-x 2 root root 116 Jun 21 09:14 swap
drwxr-xr-x 2 root root 23 Jun 21 09:14 users

3 安裝influxDB

1.1.0以后版本的influxDB沒有web頁面,筆者安裝的是influxdb-1.1.0-1.x86_64版本

influxDB參考

influxDB安裝

yum -y install https://dl.influxdata.com/influxdb/releases/influxdb-1.1.0-1.x86_64.rpm

配置參數

默認安裝路徑下,influxDB的配置文件路徑為/etc/influxdb/influxdb.conf

配置文件指明influxdb使用collectd采集器,放開8083前端端口

NOTE: This interface is deprecated as of 1.1.0 and will be removed in a future release.

配置文件中已明確,前端頁面,在1.1.0版本之后會被刪除。

~$ vim /etc/influxdb/influxdb.conf
[admin]
# Determines whether the admin service is enabled.
  enabled = true

# The default bind address used by the admin service.
  bind-address = ":8083"

# Whether the admin service should use HTTPS.
# https-enabled = false

# The SSL certificate used when HTTPS is enabled.
# https-certificate = "/etc/ssl/influxdb.pem"

###
### [http]
###
### Controls how the HTTP endpoints are configured. These are the primary
### mechanism for getting data into and out of InfluxDB.
###

[http]
# Determines whether HTTP endpoint is enabled.
  enabled = true

# The bind address used by the HTTP service.
  bind-address = ":8086"


[collectd]
  enabled = true
  bind-address = "127.0.0.1:25826"
  database = "collectd"
  typesdb = "/usr/share/collectd/types.db"

啟停influxDB

systemctl start influxdb.service
systemctl enable influxdb.service
systemctl stop influxdb.service

service influxdb status

測試influxDB

這里的數據庫無需在influxdb里事先創建好,collectd在向influxdb發送數據的時候會自動創建該數據庫。這里重啟influxdb服務,會發現其會開啟一個UDP的25826端口用來接收數據 。

檢查collectd收集的參數是否由influxDB接收

[root@node172 ~]# influx
Visit https://enterprise.influxdata.com to register for updates, InfluxDB server management, and monitoring.
Connected to http://localhost:8086 version 1.1.0
InfluxDB shell version: 1.1.0
> show databases
name: databases
name
----
_internal
collectd

> use collectd
Using database collectd
> show measurements
name: measurements
name
----
cpu_value
disk_io_time
disk_read
disk_value
disk_weighted_io_time
disk_write
interface_rx
interface_tx
load_longterm
load_midterm
load_shortterm
memory_value
swap_value

>

influxDB使用的端口

  • 8083: Web admin管理服務的端口, http://yourIP:8083

  • 8086: HTTP API的端口

  • netstat -tlnpu |grep influxd查看influxDB端口UDP協議監控

用瀏覽器查看8083端口即可訪問influxdb前端,並可用類似sql命令來訪問數據

influxdb操作參考

4 安裝grafana

grafana安裝

grafana的安裝不建議安裝低版本,版本過低,后續無法監控mysql等

建議安裝最新版本的grafana

wget https://s3-us-west-2.amazonaws.com/grafana-releases/release/grafana-5.1.4-1.x86_64.rpm 
sudo yum localinstall grafana-5.1.4-1.x86_64.rpm

官網參考

grafana啟停

systemctl stop grafana-server.service
systemctl start grafana-server.service
systemctl enable grafana-server.service

grafana頁面

web訪問頁面:

http://yourIP:3000

預制用戶admin,密碼admin,用戶可配置

下圖為已設置過的grafana面板

grafana連接數據庫

點擊Data Sources-ADD new,填寫如下參數並保存

設置grafana面板

負載設置

 

network I/O,只能切換成Switch editor mode編輯,並修改Left Y軸的單位為bytes/s,如下所示:

流入的sql腳本:

SELECT derivative("value") AS "value" FROM "interface_rx" WHERE "host" = 'client174' AND "type" = 'if_octets' AND "instance" = 'eth0'

流出時,將interface_rx改為interface_tx即可

類似配置,可配置cpu,memory,swap等

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM