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

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

前言

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

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

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

  • 安裝參考mysql

1 環境信息

172監控整個集羣linux

collectd採集數據,influxDB存儲數據,grafana展現數據web

三者關係爲:sql

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

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

influxDB和grafana安裝在172上數據庫

筆者集羣機器爲同一網段,操做系統均爲CentOS Linux release 7.4.1708 (Core) vim

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等

相關文章
相關標籤/搜索