Graphite的安装与部署

一、概述

Graphite 是一个基于Django的企业级监控工具,能实时可视化和按时间序列存储数据。严格的说,Graphite只是一个根据数据实时绘图的工具,数据收集通常通过第三方工具(如Ganglia,Collectd,StatsD,Diamond,Bucky等)或者插件完成,还可根据其他协议选用别的数据源供其绘图。我们这里只是用它做数据库存储。
Graphite包含如下三个组件:
1、Carbon:基于Twisted的进程,接受时间序列数据。Twisted框架让它能够以很低的开销处理大量的客户端和流量。主要用于监控数据,默认端口2003,外部程序StatsD通过这个端口,向Graphite输送采样的数据
2、Whisper:专门存储时间序列类型数据的小型数据库。
3、Graphite-web:一个基于Django的可以高度扩展的实时画图系统,还提供查询数据的api

二、安装环境

ubuntu 14.04 64位

三、安装步骤

1、安装方式

从源文件安装:
Graphite-Web,Carbon和Whisper的最新源代码包可以从Graphite项目下载页面获取,或者可以从Github项目页面克隆最新的.

- Graphite-web: git clone https://github.com/graphite-project/graphite-web.git
- Carbon: git clone https://github.com/graphite-project/carbon.git
- Whisper: git clone https://github.com/graphite-project/whisper.git
- wget https://launchpadlibrarian.net/104073214/check-dependencies.py #检查Graphite依赖是否缺少的程序。

在默认位置安装:
要将Graphite安装到默认位置/ opt / graphite /,只需
在每个项目目录中为Graphite-web,Carbon,Whisper和Ceres执行python setup.py install。

注意:Graphite的默认安装位置是/opt/graphite/。

1.1 安装 graphite

1.1.1 修改文件权限
    chown -R lijiajia:lijiajia /opt
1.1.2 执行 下边命令
  cd /opt/graphite-web 
  python setup.py install 
  cd carbon
  python setup.py install
  cd whisper
  python setup.py install

出现以下报错

error: [Errno 13] Permission denied: '/usr/local/lib/python2.7/dist-packages/whisper.py'

whisper需要root权限安装

cd whisper
sudo python setup.py install
1.1.3检查依赖
cd graphite-web
python check-dependencies.py

出现以下错误:

[REQUIRED] Unable to import the 'cairocffi' module, attempting to fall back to pycairo
[REQUIRED] Unable to import the 'pyparsing' module, do you have pyparsing module installed for python 2?
[REQUIRED] Unable to import the 'tagging' module, do you have django-tagging installed for python 2?
[OPTIONAL] Unable to import the 'memcache' module, do you have python-memcached installed for python 2? This feature is not required but greatly improves performance.
[OPTIONAL] Unable to import the 'ldap' module, do you have python-ldap installed for python 2? Without python-ldap, you will not be able to use LDAP authentication in the graphite webapp.
[OPTIONAL] Unable to import the 'txamqp' module, this is required if you want to use AMQP as an input to Carbon. Note that txamqp requires python 2.5 or greater.
[OPTIONAL] Unable to import the 'python-rrdtool' module, this is required for reading RRD.
[OPTIONAL] Unable to import the 'whitenoise' module. This is useful for serving static files.
[OPTIONAL] Unable to import the 'pyhash' module. This is useful for fnv1_ch hashing support.
6 optional dependencies not met. Please consider the optional items before proceeding.
2 necessary dependencies not met. Graphite will not function until these dependencies are fulfilled.

说明依赖包缺少,需要安装 REQUIRED为必须的依赖包,OPTIONAL为可选的依赖包

1.1.4 安装依赖

执行以下命令安装依赖包

sudo pip install cairocffi
sudo pip install pyparsing
sudo pip install tagging   
sudo pip intall python-memcached
sudo pip  install ldap
sudo pip install txamqp
sudo apt-get install librrd-dev #安装rrdttol的依赖
sudo pip install python-rrdtool
sudo pip install whitenoise
#pyhash需要c++依赖,暂不安装,不影响使用。

1.2 安装后graphite的目录

graphite
├── bin       #二进制文件目录,可执行文件目录
├── conf      #配置文件目录
├── examples  #获取数据的例子
├── lib       #库目录
├── storage   #数据存放目录,包括log,whisper数据库,索引,rrd数据等
└── webapp    #webapp文件存放目录

1.3 配置graphite

执行以下命令

cd /opt/graphite/conf
cp carbon.conf.example carbon.conf
cp storage-schemas.conf.example storage-schemas.conf
cp graphite.wsgi.example  ../webapp/graphite/graphite_wsgi.py
cd /opt/graphite/webapp/graphite
cp local_settings.py.example local_settings.py

修改local_settings.py

SECRET_KEY = 'Hard to guess ' #此密钥用于验证授权令牌,CRSF中间件,cookie存储等中使用的哈希。如果在负载平衡器后面使用,则应该在所有节点中对其进行相同设置。
ALLOWED_HOSTS = [ '*' ]
TIME_ZONE = 'Asia/Shanghai'
DATABASES = {
    'default': {
        'NAME': 'youdb',
        'ENGINE': 'django.db.backends.mysql',
        'USER': 'youuser',
        'PASSWORD': 'youpasswd',
        'HOST': 'youhost',
        'PORT': 3306
    }
}

1.4 初始化数据库

PYTHONPATH=/opt/graphite/webapp django-admin.py migrate --settings=graphite.settings --run-syncdb

出现报错

File "/opt/graphite/webapp/graphite/events/models.py", line 4, in <module>
    from tagging.models import Tag
  File "/usr/local/lib/python2.7/dist-packages/tagging/models.py", line 5, in <module>
    from django.contrib.contenttypes import generic
ImportError: cannot import name generic

原因是没有安装Tag模块

sudo pip install django-tagging

再次初始化数据库出现报错:

ImportError: No module named scandir

安装缺少模块:

sudo pip install scandir

再次初始化数据库,成功。

四 启动graphite

cd /opt/graphite/webapp/graphite
gunicorn graphite_wsgi:application -b 0.0.0.0:12546

注:正式环境需要Nginx+gunicorn配置

五 访问graphite-web

http://192.168.1.89:12546/
这里写图片描述

六 启动cabon

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

七 向Graphite发送数据

graphite默认接收数据的端口是2003。
/opt/graphite/examples目录下有个测试用例。
执行:

   python example-client.py   

显示:

system.loadavg_1min 0.16 1516773121
system.loadavg_5min 0.09 1516773121
system.loadavg_15min 0.06 1516773121

()
sending message

对应在浏览器窗口中的显示为在system目录下,loadavg_15min、loadavg_5min、loadavg_1min这三条线就是example-client.py的数据产生的图形。
效果如下:
这里写图片描述

注意事项:默认显示24小时,因此可能好像没有图形出现,可以点击上图所示红色框范围选择时间范围。

样例所产生的数据在下边目录下:

/opt/graphite/storage/whisper/system
loadavg_15min.wsp  loadavg_1min.wsp  loadavg_5min.wsp

可以使用以下命令查看whisper中的数据:

whisper-dump.py loadavg_1min.wsp
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值