Influxdb+collectd+grafana搭建現代化監控系統
阿新 • • 發佈:2019-02-11
在此採用centos+Influxdb+collectd+grafana搭建監控系統,特此說明下influxdb的0.9,0.10,0.11,0.12均不支援delect功能,0.8和0.13支援delect功能,其實最主要的區別是0.9版本和0.10版本,0.10更改了資料儲存引擎,能夠節省大量空間,查詢速度也快了很多,所以第一次安裝的話最好優先選擇0.10及以上版本,在此,個人採用0.13。
第一步安裝centos7 ,在此不描述。
第二步安裝influxdb:
# cat <<EOF | sudo tee /etc/yum.repos.d/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
EOF
# yum install -y influxdb
# mkdir -p /home/influxdb/data
# chown -R influxdb:influxdb /home/influxdb
以上兩條命令建立的目錄是用來儲存influxdb的資料。個人建議,將influxdb的資料放在最大的分割槽內,collectd預設安裝後每10秒生成一組資料,資料量還是蠻大的。
修改配置檔案:
# cat /etc/influxdb/influxdb.conf
[data]
# Controls if this node holds time series data shards in the cluster
enabled = true
dir = "/home/influxdb/data"
然後啟動influxdb:
# service influxdb start
# service influxdb status
第三步安裝collectd:
# yum install epel-release -y
# yum install -y collectd
# cat /etc/collectd.conf
Hostname "localhost"
TypesDB "/usr/share/collectd/types.db"
LoadPlugin network
<Plugin network>
Server "172.16.17.129" "25826"
</Plugin>
啟動collectd:
# service collectd start
# service collectd status
第四步安裝grafana:
grafana依賴fontconfig
# yum -y install fontconfig
# wget https://grafanarel.s3.amazonaws.com/builds/grafana-3.1.1-1470047149.x86_64.rpm
# rpm -ivh grafana-3.1.1-1470047149.x86_64.rpm
# service grafana-server start
# service grafana-server status
啟動grafana後,修改下influxdb的配置檔案,以便influxdb和collectd聯通:
# cat /etc/influxdb/influxdb.conf
[[collectd]]
enabled = true
# service influxdb restart
# service influxdb status
可通過以下步驟檢驗collectd是否將資料儲存在influxdb中:
# influx
> show databases;
name: databases
---------------
name
collectd
_nternal
> use collectd;
Using database collectd
> show MEASUREMENTS
name: measurements
------------------
name
cpu_value
interface_rx
interface_tx
load_longterm
load_midterm
load_shortterm
memory_value
> select * from cpu_value limit 10;
name: cpu_value
---------------
time host instance type type_instance value
1469886342535694000 localhost 0 cpu user 241563
1469886342535705000 localhost 0 cpu system 63684
1469886342535709000 localhost 0 cpu wait 58022
1469886342535713000 localhost 0 cpu nice 23
1469886342535717000 localhost 0 cpu interrupt 0
1469886342535721000 localhost 0 cpu softirq 17027
1469886342535722000 localhost 0 cpu steal 0
1469886342535723000 localhost 0 cpu idle 4.461107e+06
1469886352534453000 localhost 0 cpu user 241593
1469886352534462000 localhost 0 cpu system 63693
通過如上步驟,可見influxdb和collectd已相連線。
下一步grafana和influxdb相連。
grafana的埠號是3000,開啟web介面:http://172.16.17.129:3000 ,預設賬戶,密碼為admin/admin。登陸後介面如下:
需要對influxdb連通,進行相關配置:
開啟data source:
填寫結果如下所示,密碼賬號分別為root,root:
目前基本安裝已完成。