环境 : CentOS6.0_x64
安装成功的版本0.9.9
包含:
A check-dependencies.py
B carbon-0.9.9.tar.gz
C whisper-0.9.9.tar.gz
D graphite-web-0.9.9.tar.gz
carbon is responsible for receiving metrics over the network and writing them down to disk using a storage backend
通过网络接收数据并且写入磁盘
默认监听端口是2003
metrics 数据格式:
whisper is our stable, supported backend
whisper为后台程序
graphite-web
该模块可以最先安装,然后通过浏览器即可访问,当然是空的,没有数据。
执行:find / -name '*.sock'
查找出wsgi相应pid保存的位置,出现以下结果:
/var/run/cups/cups.sock
/var/run/httpd/wsgi.14539.0.1.sock
/var/run/rpcbind.sock
也即加粗的第二项,接下来,把/etc/httpd/conf.d/graphite-vhost.conf 中的WSGISocketPrefix一栏做出相应的修改:
WSGISocketPrefix /var/run/httpd/wsgi
使用CenOS系统包装好wsgi后会有错误,在log中可以看到:
Exception KeyError: KeyError(140694880159712,) in <module 'threading' from '/usr/lib64/python2.6/threading.pyc'> ignored
该错误由wsgi与python内部问题导致,该错误不会影响程序正常执行,不必理会。
本地yum源除外,还缺少一下依赖包
Django-1.2.7.tar.gz
django-tagging-0.3.1.tar.gz
txAMQP-0.6.2.tar.gz
给graphite喂数据:
安装好Graphite之后,Carbon处于Listening状态,等待App 的Data Feed,以便使用Cairo进行绘图(Graphing)。
参考如下文章即可:
http://www.webtrest.com/?p=5
http://wsq68.blog.51cto.com/2394336/1282517
collectl -scdnNms -i5 --netfilt "eth\d" --export graphite,ip
参考:
http://docs.hostedgraphite.com/
给一个客户端向主机发送CPU,RAM心跳包的Python代码:
import psutil import time import socket #function of Get CPU State def getCPUstate(interval=1): return str(psutil.cpu_percent(interval)) #function of Get Memory def getMemorystate(): phymem = psutil.phymem_usage() buffers = getattr(psutil, 'phymem_buffers', lambda: 0)() cached = getattr(psutil, 'cached_phymem', lambda: 0)() used = phymem.total - (phymem.free + buffers + cached) line = "%5s%% %6s/%s" % ( phymem.percent, str(int(used / 1024 / 1024)) + "M", str(int(phymem.total / 1024 / 1024)) + "M" ) return phymem.percent def collect_metric(name, value, timestamp): sock = socket.socket() sock.connect( ("172.18.14.41", 2003) ) sock.send("%s %d %d\n" % (name, value, timestamp)) sock.close() def get_time(): return int(time.time()) while 1: time1 = get_time() #collect_metric("wangjianpc", 42, now()) cpu_state = getCPUstate() mem_state = getMemorystate() #print cpu_state #print mem_state msg = "wangjianpc" + ".CPU " + cpu_state + " " + str(time1) + "\n" + "wangjianpc.RAM " + str(mem_state) + " " + str(time1) + "\n" print msg sock = socket.socket() sock.connect( ("172.18.14.41", 2003) ) sock.send("%s" % (msg)) sock.close() time.sleep(5)