Grafana collectd InfluxDB

安裝部分:

server端:192.168.99.135 
安裝程序:InfluxDB Grafana

Client端:192.168.99.136

安裝程序:Collectd


server端

一、influxdb安裝

(1)配置YUM源
cat <<EOF |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

(2)安裝和啓動
#yum install -y influxdb 
#service influxdb start



(3)相關信息
web後臺http://192.168.99.135:8083/

API接口 192.168.99.135:8086
配置文件路徑:/etc/influxdb/influxdb.conf

# 找到admin,將前面的#號去掉,開放它的UI端口

[admin]
  # Determines whether the admin service is enabled.
  enabled = true
  # The default bind address used by the admin service.
  bind-address = ":8083"
#service influxdb restart



二、grafana安裝

http://docs.grafana.org/installation/rpm/

Install via YUM Repository

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

yum install grafana

注:

1.從官網下載最新的軟件包

2.若系統中使用yum安裝較慢的話,可以使用迅雷下載完成之後上傳至服務器中。


(2)修改配置
日誌路徑:
/var/log/grafana/grafana.log

配置文件路徑:
/etc/grafana/grafana.ini

#vim /etc/grafana/grafana.ini

//由於默認端口3000和我測試環境的一個程序衝突,所以修改默認服務端口爲
http_port = 3001
#/etc/init.d/grafana-server restart

# netstat  -an|grep 3001

tcp        0      0 :::3001                     :::*                        LISTEN


啓動服務後訪問 http://192.168.99.135:3001


Client端

collectd安裝,大部分Linux版本自帶的YUM源都有此軟件

# yum install epel-release
# yum install collectd




配置部分:

InfluxDB開啓collectd插件

InfluxDB 現在自帶一個 collectd 插件來獲取 collectd 客戶端發來的數據,以前可沒這麼方便哦,0.8.4 版本以前只能通過 influxdb-collectd-proxy 這樣的第三方程序來連接 collectd 和 InfluxDB. 

InfluxDB 自帶的 collectd 插件默認是關閉的,需要手動配置打開 enabled = true,並填上 database = “collectd” 這一行,這裏的 “collectd” 就是我們上面創建的那個數據庫,更改配置後記得重啓 InfluxDB

修改配置重啓後會發現 influxdb 插件啓動了一個 25826 端口,如果發現 InfluxDB 數據庫裏沒有(收集到)數據,務必檢查這個 25826 端口是否正常啓動了。


編輯 InfluxDB 的配置文件 /etc/opt/influxdb.conf,將 [collectd] 標籤下的內容修改爲:

#vim /etc/influxdb/influxdb.conf
`collectd`           //這裏需要兩個括號,不然啓動會報錯
 enabled = true
 bind-address = ":25826"
 database = "collectd"
 typesdb = "/usr/share/collectd/types.db"

 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" # will flush at least this often even if we haven't hit buffer limit
 read-buffer = 0 # UDP Read buffer size, 0 means OS default. UDP listener will fail if set above OS max.


#service influxdb restart

# tail -f /var/log/influxdb/influxd.log

[collectd] 2016/12/12 17:52:52 Starting collectd service

[collectd] 2016/12/12 17:52:52 Loading /usr/share/collectd/types.db

[collectd] 2016/12/12 17:52:52 Listening on UDP:  [::]:25826

[run] 2016/12/12 17:52:52 Listening for signals

[monitor] 2016/12/12 17:52:52 Storing statistics in database '_internal' retention policy 'monitor', at interval 10s

2016/12/12 17:52:52 Sending usage statistics to usage.influxdata.com




# netstat  -an|grep 25826

udp        0      0 :::25826                    :::*




你可以驗證下 InfluxDB 是否已經收到了 Collectd 發送的監控信息:


# influx

Visit https://enterprise.influxdata.com to register for updates, InfluxDB server management, and monitoring.

Connected to http://localhost:8086 version 1.1.1

InfluxDB shell version: 1.1.1

> show databases;

name: databases

name

----

_internal

testdb

collectd

grafana


> use collectd;

Using database collectd

> show measurements

name: measurements

name

----

cpu_value

interface_rx

interface_tx

load_longterm

load_midterm

load_shortterm

memory_value





二、創建collectd數據庫

登錄 http://192.168.99.135:8083/  創建數據庫名爲collectd和grafana的數據庫,輸入語句按下回車即可

wKioL1hOeGTD5KSoAACEpNjTARI292.png-wh_50

wKioL1hOd_3A9I1fAABrtLIm79o278.png-wh_50




client端配置collectd


FQDNLookup  true
BaseDir     "/var/lib/collectd"
PIDFile     "/var/run/collectd.pid"
PluginDir   "/usr/lib64/collectd"
TypesDB     "/usr/share/collectd/types.db"
LoadPlugin  syslog
LoadPlugin  interface
LoadPlugin  load
LoadPlugin  network
<Plugin interface>
Interface "eth0"
IgnoreSelected false
</Plugin>
<Plugin load>
    ReportRelative true
</Plugin>
<Plugin network>
    Server "127.0.0.1" "25826"
</Plugin>


最關鍵的是 “network” plugin,這部分設定監控信息將要發送到 127.0.0.1 的 25826 端口。稍後我們將要指定 InfluxDB 監聽此端口以接收 collectd 的發包。

現在啓動這個守護程序,並且將它加入到開機自啓動中。

# /etc/init.d/collectd  restart
# chkconfig  collectd on
# chkconfig  collectd --list 
collectd       	0:off	1:off	2:on	3:on	4:on	5:on	6:off




客戶端啓動服務:
/etc/init.d/collectd restart


這時候可以上influxdb數據庫服務器上查看是否有數據傳輸過來,可以命令行查看也可上WEB頁面查看

http://192.168.99.135:8083/

wKioL1hOesyBaZ2dAAC9L6km2t4702.png-wh_50


命令行查看:

# influx

Visit https://enterprise.influxdata.com to register for updates, InfluxDB server management, and monitoring.

Connected to http://localhost:8086 version 1.1.1

InfluxDB shell version: 1.1.1

> show databases;

name: databases

name

----

_internal

collectd

grafana


> 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 /load/;

name: load_longterm

time host type value

---- ---- ---- -----

1481536366000000000 node01.example.com load 0

1481536376000000000 node01.example.com load 0

1481536386000000000 node01.example.com load 0

1481536396000000000 node01.example.com load 0

1481536406000000000 node01.example.com load 0

1481536416000000000 node01.example.com load 0

1481536426000000000 node01.example.com load 0

1481536436000000000 node01.example.com load 0



grafana配置數據源


點擊 Data Source 然後 Add new,填寫如下配置項

wKioL1hOghTx6fLvAAGnip3SxD0366.png-wh_50


官網參考文檔:http://docs.grafana.org/
官方演示地址:http://play.grafana.org/


未完待續。。。



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