一、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組件:whisper、carbon、graphite-web
安裝方式:源代碼、pip、virtualenv(本例使用源碼安裝)
下載文件
安裝方法(默認安裝位置/opt/graphite目錄)
whisper、carbon、graphite-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.conf是carbon的配置文件,分三個片段cache、relay和aggregator
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_15min、loadavg_5min、loadavg_1min這三條線就是example-client.py的數據產生的圖形
注意事項:默認顯示24小時,因此可能好像沒有圖形出現。可以點擊上圖中右箭頭選擇時間範圍,如下圖:
6、常見問題(網上找到的)
解決辦法: 打開http://cairographics.org/pycairo/, 有個pycairo和py2cairo
解決辦法: 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
解決辦法: yum install mod_python
解決辦法: yum install python-memcached
問題8: 不能導入ldap模塊
解決辦法: yum install python-ldap
解決辦法: yum install python-twisted
解決方法: 到https://launchpad.net/txamqp/下載txamqp模塊,然後運行python
setup.py install安裝即可
解決辦法:
運行建立數據庫命令,且將新建立的數據庫文件修改成爲httpd服務(apache或httpd等)運行的用戶,最好將整個/opt/graphite修改爲httpd服務運行的用戶
7、參考文章
二、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是以插件方式對各個組件進行監控的,在編譯前可以使用以下命令查看模塊:
3、collectd配置
[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插件
啓動collectd服務
[root@collectd ~]#
/usr/local/collectd/sbin/collectd
這樣就完成了,collectd會收集數據,將數據發送給graphite的carbon監聽端口(默認爲2003)Graphite將根據數據繪製圖形。
5、多機監控
多機監控其實也非常簡單,就是按照上述步驟在多臺被監控機上安裝配置collectd即可
但是一定要注意時間同步問題,將時間同步之後再重啓一下collectd守護進程即可
(圖片版請看附件)