graphite 安装使用笔记

本文介绍如何在CentOS 6.0环境下安装Graphite监控系统,包括安装必要组件如Carbon、Whisper及Graphite Web,并提供了配置过程及常见错误解决办法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

环境 : CentOS6.0_x64



安装成功的版本0.9.9


包含:

A check-dependencies.py

B carbon-0.9.9.tar.gz           

whisper-0.9.9.tar.gz

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

通过网络接收数据并且写入磁盘

netstat -an | grep 2003
默认监听端口是2003


metrics 数据格式:

metricname value [timestamp]
  • metricname is a period-delimited path, such as servers.mario.memory.free The periods will turn each path component into a sub-tree. The graphite project website has some metric naming advice.
  • value is an integer or floating point number. 整型或者浮点型的数字
  • timestamp (optional) is a UNIX timestamp, which is the number of seconds since Jan 1st 1970 (always UTC, never local time). If no timestamp is provided, the current time will be assumed. This is probably “good enough” for most uses.时间戳,如果不加则使用graphite所在的系统时间
You can send multiple metric values at the same time by putting them on separate lines in the same message:发送多行数据的方式

conc_users 59
free_ram 33


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)






评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值