Graphite和collectd 建立監控服務器

一、Graphite準備

1、安裝依賴包

 
[root@collectd ~]# yum install -y bitmap bitmap-fonts-compat Django django-tagging fontconfig cairo python-devel python-memcached python-twisted  pycairo mod_python python-ldap python-simplejson memcached python-zope-interface mod_wsgi python-sqlite2 git gcc gcc-c++ make

 
2、安裝Graphite組件

Graphite組件:whispercarbongraphite-web

安裝方式:源代碼、pipvirtualenv(本例使用源碼安裝)

 
下載文件

 
安裝方法(默認安裝位置/opt/graphite目錄)

whispercarbongraphite-web安裝方法相同,解壓軟件,進入軟件目錄,執行以下命令

[root@collectd soft]# tar zxvf carbon-0.9.10.tar.gz

[root@collectd soft]# cd carbon-0.9.10

[root@collectd carbon-0.9.10]# python setup.py install

 
[root@collectd soft]# tar zxvf graphite-web-0.9.10.tar.gz

[root@collectd soft]# cd graphite-web-0.9.10

[root@collectd graphite-web-0.9.10]# python setup.py install

 
[root@collectd soft]# tar zxvf whisper-0.9.10.tar.gz

[root@collectd soft]# cd whisper-0.9.10

[root@collectd whisper-0.9.10]# python setup.py install

 
3、配置graphite

1)設置graphite配置文件

[root@collectd ~]# cd /opt/graphite/conf/

[root@collectd conf]# cp carbon.conf.example carbon.conf

[root@collectd conf]# cp storage-schemas.conf.example storage-schemas.conf

[root@collectd conf]# cp graphite.wsgi.example graphite.wsgi

其中:

         /opt/graphite/conf是配置文件存放目錄

carbon.confcarbon的配置文件,分三個片段cacherelayaggregator

storage-schemas.conf配置文件定義數據的存儲

graphite.wsgi配置文件配置django

2)設置apache虛擬主機

apache虛擬主機配置有一個樣例在graphite-web安裝包內的examples/example-graphite-vhost.conf,複製這個文件到apache配置文件

 
下圖爲虛擬主機配置文件


 
3)初始化數據庫

[root@collectd ~]# cd /opt/graphite/webapp/graphite

[root@collectd graphite]# cp local_settings.py.example local_settings.py

[root@collectd graphite]# python manage.py syncdb

[root@collectd graphite]# chown -R apache.apache /opt/graphite/




4)啓動apache服務

[root@collectd ~]# service httpd start

 
5)啓動carbon

[root@collectd ~]# cd /opt/graphite/

[root@collectd graphite]# ./bin/carbon-cache.py start

 
4、安裝測試

瀏覽器訪問 172.16.19.105:8080 地址後就可以看到 graphite web 界面。如下圖:

 
 
 
 
 
 
 
 
 
5、運行graphite-web安裝包內的examples/example-client.py可以喂數據給graphite

[root@collectd examples]# python example-client.py

產生的數據格式如下:

 
 
 
對應在瀏覽器窗口中的顯示爲在system目錄下,loadavg_15minloadavg_5minloadavg_1min這三條線就是example-client.py的數據產生的圖形

注意事項:默認顯示24小時,因此可能好像沒有圖形出現。可以點擊上圖中右箭頭選擇時間範圍,如下圖:

 

 
6、常見問題(網上找到的)

問題1pycairo安裝提示python版本太低

解決辦法打開http://cairographics.org/pycairo/, 有個pycairopy2cairo

問題2: 安裝py2cairo提示python2.6未發現或cairo模塊未發現

解決辦法:  yum install pycairo python-devel

 
問題3: cairo模塊需要字體

[FATAL] Failed to create text with cairo, this probably means cairo cant find any fonts. Install some system fonts and try again

解決辦法:  yum install bitmap-fonts-compat

 
問題4: 不能導入django模塊

解決辦法:   yum install Django

 
問題5: 不能導入tagging模塊

解決辦法:   yum install django-tagging

 
問題6: 不能導入mod_python模塊

解決辦法:   yum install mod_python

 
問題7: 不能導入memcache模塊

解決辦法:  yum install python-memcached

問題8: 不能導入ldap模塊

解決辦法:   yum install python-ldap

 
問題9: 不能導入twisted

解決辦法:   yum install python-twisted

 
問題10: 不能導入txamqp模塊

解決方法:   https://launchpad.net/txamqp/下載txamqp模塊,然後運行python setup.py install安裝即可

 
問題11DatabaseError: attempt to write a readonly database

解決辦法: 運行建立數據庫命令,且將新建立的數據庫文件修改成爲httpd服務(apachehttpd)運行的用戶,最好將整個/opt/graphite修改爲httpd服務運行的用戶

7、參考文章

Installing Graphite - Graphite 官方網站的安裝指南

Installing Graphite - Graphite 文檔網站 的安裝指南

 
二、collectd安裝

 
1、安裝依賴包

[root@collectd ~]# yum -y install perl-ExtUtils-MakeMaker

 
2、安裝collectd

[root@collectd soft]# tar jxvf collectd-5.1.1.tar.bz2

[root@collectd soft]# cd collectd-5.1.1

[root@collectd collectd-5.1.1]# ./configure --prefix=/usr/local/collectd --enable-cpu --enable-memory --enable-ping --enable-swap

[root@collectd collectd-5.1.1]# make && make install

注意collectd是以插件方式對各個組件進行監控的,在編譯前可以使用以下命令查看模塊:

[root@collectd collectd-5.1.1]# ./configure –help

目前還沒有發現collectd是否可以在安裝collectd完成之後再動態的添加插件

3collectd配置

[root@collectd ~]# vi /usr/local/collectd/etc/collectd.conf

collectd.conf中添加以下行:

Include      "/usr/local/collectd/etc/collectd.d"

 
創建collectd.d配置目錄

[root@collectd ~]# mkdir /usr/local/collectd/etc/collectd.d

 
添加/usr/local/collectd/etc/collectd.d/graphite.conf 配置文件,文件內容如下:

[root@collectd ~]# vi /usr/local/collectd/etc/collectd.d/graphite.conf

 
 
 
 
 
 
 
4、安裝collectd-carbon插件

[root@collectd ~]# git clone https://github.com/indygreg/collectd-carbon.git /usr/local/collectd/plugins/

 
啓動collectd服務

[root@collectd ~]# /usr/local/collectd/sbin/collectd

 
這樣就完成了,collectd會收集數據,將數據發送給graphitecarbon監聽端口(默認爲2003Graphite將根據數據繪製圖形。

5、多機監控

多機監控其實也非常簡單,就是按照上述步驟在多臺被監控機上安裝配置collectd即可

但是一定要注意時間同步問題,將時間同步之後再重啓一下collectd守護進程即可

 
6、監控效果圖如下





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