一、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、常见问题(网上找到的)
问题1:pycairo安装提示python版本太低
解决办法:打开http://cairographics.org/pycairo/,有个pycairo和py2cairo
问题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安装即可
问题11:DatabaseError: attempt to write a readonly database
解决办法:
运行建立数据库命令,且将新建立的数据库文件修改成为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是以插件方式对各个组件进行监控的,在编译前可以使用以下命令查看模块:
[root@collectd collectd-5.1.1]# ./configure –help
目前还没有发现collectd是否可以在安装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插件
[root@collectd ~]# git clone
https://github.com/indygreg/collectd-carbon.git /usr/local/collectd/plugins/
启动collectd服务
[root@collectd ~]#
/usr/local/collectd/sbin/collectd
这样就完成了,collectd会收集数据,将数据发送给graphite的carbon监听端口(默认为2003)Graphite将根据数据绘制图形。
5、多机监控
多机监控其实也非常简单,就是按照上述步骤在多台被监控机上安装配置collectd即可
但是一定要注意时间同步问题,将时间同步之后再重启一下collectd守护进程即可
6、监控效果图如下
(图片版请看附件)