现在的位置: 首页 > 综合 > 正文

WEB监控系列第二篇:web监控搭建——graphite+statsd(服务器上搭建)

2012年11月22日 ⁄ 综合 ⁄ 共 5228字 ⁄ 字号 评论关闭

转贴请注明原址:http://blog.csdn.net/crazyhacking/article/details/8464235

1 说明

(1)因为1 想安装在一个目录下 2不能使用root权限.

使用virtualenv环境:http://www.cnblogs.com/cheungjustin/archive/2011/12/08/2281041.html

和pip/easy-install安装

进入 virtual环境,然后安装其它包。

(virtualenv的最大好处是不能使用yum等命令时----鉴于权限所致,可以使用pip等一键安装命令;第二大好处是安装到一个目录下)

(2)Installing in Virtualenv

Virtualenv provides an isolated Python environment to run Graphite in.

To install Graphite in the
default location
, /opt/graphite/,create a virtualenv in/opt/graphite and activate it:

virtualenv /opt/graphite   #建立一个虚拟环境
source /opt/graphite/bin/activate #激活这个环境

Once the virtualenv is activated, Graphite and Carbon can be installedfrom source orvia
pip

(3)安装 Graphite-web和carbon(感觉和virtualenv无关)

安装graphite

https://graphite.readthedocs.org/en/latest/install-source.html#graphite-web-custom-location-source

python setup.py install --prefix=/srv/graphite --install-lib=/srv/graphite/webapp

安装carbon

python setup.py install --prefix=/srv/graphite --install-lib=/srv/graphite/lib

(4)后台使用uwsgi

2 具体安装

安装的原则有两条:注意看软件包的说明文件,并且注意处理安装过程中报的错误

(1)下载

四个包 graphite-web-0.9.10 carbon-0.9.10 whisper-0.9.10 check-dependencies.py

(2) 检查依赖,安装所需的依赖包。

安装的原则是能用virtualenv下的pip命令安装的尽量这样安装,因为 pip会自动安装依赖包。

不能pip安装的,则下载源码,安装,configure  --prefix=path/to/install/

最后,只有两个依赖包没有装$python check-dependencies.py
[WARNING] Unable to import the 'mod_python' module, do you have mod_python installed for python 2.7.3?
mod_python is one of the most common ways to run graphite-web under apache.
Without mod_python you will still be able to use the built in development server; which is not
recommended for production use.
wsgi or other approaches for production scale use are also possible without mod_python
[WARNING]
Unable to import the 'ldap' module, do you have python-ldap installed for python 2.7.3?
Without python-ldap, you will not be able to use LDAP authentication in the graphite webapp.

All necessary dependencies are met.
2 optional dependencies not met. Please consider the warning messages before proceeding.

(3)安装 graphite

(1)进入graphite安装包,检查依赖check-dependencies.py

(2)修改路径setup.cfg.prefix =

(3)编译,安装setup.py build  ,  setup.py install

 (4)安装后加入路径

export PYTHONPATH=$PYTHONPATH:$GRAPHITE_ROOT/webapp
 cd $GRAPHITE_ROOT/webapp/graphite/
 (5)初始化数据库 

1
2
3
4
cd /opt/graphite/webapp/graphite/
cp local_settings.py.example local_settings.py
python manage.py syncdb
chown -R apache.apache /opt/graphite

(6)启动graphite

/opt/bre/LogCollector/software/graphite/bin/run-graphite-devel-server.py --libs=/opt/bre/LogCollector/software/graphite/webapp/ /opt/bre/LogCollector/software/graphite/ &

(7)查看 http://192.168.32.127:8080/

(8)测试,echo "local.random.diceroll 4 `date +%s`" | nc ${SERVER} ${PORT};查看(7)打开的界面的反应。

(4)carbon

修改配置路径setup.cfg,把carbon装到grapgite一个目录下。安装carbon

启动cabon

1
2
cd /opt/graphite/
./bin/carbon-cache.py start

(5) whisper

使用pip安装

(6)statsd

(直接用pip安装不知道为啥没有几个文件,所以还是git 复制了)

(如果没有node.js需要先安装)

git clone git://github.com/etsy/statsd.git

cp exampleConfig.js Config.js

修改配置文件Config.js中graphiteHost: "127.0.0.1"

启动服务 node stats.js Config.js &

把statsd模块加入环境变量PYTHONPATH中

使用statsd:

python

import statsd

3 使用graphite和statsd

修改存储格式存储statsd发过来的数据,格式为stats.*

storage-schemas.conf中:

[stats]
 11 priority = 110
 12 pattern = ^stats\..*
 13 retentions = 10s:6h,1m:7d,10m:1y

(10s的作为一个数据点存储(存储时10秒内的平均值),存储6个小时的数据;1分钟的存储为一个数据,存储7天;10分钟的是一个数据点,存储1年)

2 启动statsd

python

import statsd

ccc=statsd.client.StatsClient(host='127.0.0.1',port=8125)#链接

ccc.incr("hello",5)#

4 问题

1 安装py2cairo时  ,一直提示Could not find the python development headers,

解答:LDFLAGS="-lm -ldl -lutil" ./waf configure --prefix=

参考: http://url.cn/7LWGFM

2 安装cairo时候,找不到pixman,但其实已经安装

问题症状:checking whether cairo's image surface backend feature could be enabled... no (requires pixman-1 >= 0.18.4 http://cairographics.org/releases/)
configure: error: mandatory image surface backend feature could not be enabled

解决:

With pixman already installed:
-bash-3.2$ export PKG_CONFIG_PATH=/usr/local/lib64/lib/pkgconfig/

然后把pixman中包含*.pc的文件路径包括进去。
export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/opt/bre/LogCollector/software/pixman-0.28.2/lib/pkgconfig

 -bash-3.2$ pkg-config --modversion pixman-1
0.18.4

参考:理解 pkg-config 工具

3   安装cairo 时候,cairo-gobject-enums.c:14: error: implicit declaration of function 'g_once_init_enter'

解决:./configure --disable-valgrind          --disable-gobject

参考:http://lists.freedesktop.org/archives/cairo/2011-February/021660.html

4检查依赖时候,发现找不到cairo,但是已经安装了py2cairo和cairo

[FATAL] Unable to import the 'cairo' module, do you have pycairo installed for python 2.7.3?

解决:修改环境变量PYTHONPATH=$PYTHONPATH:/LogCollector/software/py2cairo-1.10.0/lib/python2.7/site-packages/

5在初始化数据库这一步,python manage.py syncdb出现“settings.DATABASES is improperly
configured” error performing syncdb with django 1.4

解答:这是软件版本不兼容的问题。settings.py中定义的database的格式对于django1.4来说过时,解决方法是把local_settings 中的新格式启用

(去掉注释符)

DATABASES = {
    'default': {
        'NAME': '/opt/bre/LogCollector/software/graphite/storage/graphite.db',
        'ENGINE': 'django.db.backends.sqlite3',
        'USER': '',
        'PASSWORD': '',
        'HOST': '',
        'PORT': ''
    }   
}

参考:http://stackoverflow.com/questions/10228618/settings-databases-is-improperly-configured-error-performing-syncdb-with-djang

5本来是用好好的。在初始化数据库这一步,python manage.py syncdb出现 ImportError: cannot import name parse_lookup

解决django-tagging版本太低,使用pip freeze查看,得到0.2.1。

升级版本:pip install django-tagging==0.3.1

参考:http://stackoverflow.com/questions/346426/installation-problems-with-django-tagging

6启动statsd时报错误:Error: listen EADDRINUSE

node stats.js Config.js:

events.js:48
throw arguments[1]; // Unhandled ‘error’ event
^
Error: listen EADDRINUSE

解答:根据报错信息,EADDRINUSE 说明端口被占用。查询进程和端口得知node已经启动过了,结束掉重新启用

抱歉!评论已关闭.