graphite 安装使用

简介:

Graphite 是一款开源的监控绘图工具。

Graphite 可以实时收集、存储、显示时间序列类型的数据(time series data)。它主要有三个部分构成:

  1. carbon —— 基于 Twisted 的进程,用来接收数据;

  2. whisper —— 专门存储时间序列类型数据的小型数据库;

  3. graphite webapp —— 基于 Django 的网页应用程序。

下面主要说明一下graphite的安装:

一、使用pip 安装graphite:

1.安装Graphite所依赖的一些软件:

1)安装系统依赖

	
yum install cairo-devel.x86_64 fontconfig.x86_64 python-devel libffi-devel.x86_64 mysql-devel.x86_64

2)安装pip:

3)安装graphite依赖的一些python包:

      pip install -r requirements.txt

14

15

cairocffi==0.7.2

cffi==1.5.2

Django==1.6.8

django-tagging==0.3.6

MySQL-python==1.2.3

pycparser==2.14

pyparsing==1.5.6

python-memcached==1.57

pytz==2015.7

six==1.10.0

Twisted==16.0.0

txAMQP==0.6.2

uWSGI==2.0.12

whisper==0.9.15

zope.interface==4.1.3

 

2.利用源码安装graphite(源码安装是最新的版本):

graphite默认的安装路径是/opt/graphite:

1)Graphite-web: git clone https://github.com/graphite-project/graphite-web.git

2)Carbon: git clone https://github.com/graphite-project/carbon.git

3)Whisper: git clone https://github.com/graphite-project/whisper.git

4)Ceres: git clone https://github.com/graphite-project/ceres.git

 

3.安装graphite web:

1)安装配置 nginx

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

[root@test123 graphite]# cat /etc/nginx/conf.d/graphite.conf

server {

        listen        8000;

        server_name   10.13.40.216;

        charset       utf-8;

        access_log    /var/log/nginx/graphite.access.log;

        error_log     /var/log/nginx/graphite.error.log;

        location / {

            add_header Access-Control-Allow-Origin $http_origin;

            add_header 'Access-Control-Allow-Credentials' 'true';

            add_header 'Access-Control-Allow-Methods' 'GET, OPTIONS';

            add_header 'Access-Control-Allow-Headers' 'origin, authorization, accept';

            uwsgi_pass 127.0.0.1:3031;

            include uwsgi_params;

        }

        location /static {

            alias /opt/graphite/webapp/content;

        }

        location /content {

            alias /opt/graphite/webapp/content;

            gzip off;

            include uwsgi_params;

            uwsgi_pass      127.0.0.1:3031;

        }

}

2)配置uwsgi.

1

2

3

4

5

6

7

8

9

10

11

12

13

[root@test123 graphite]# cat /opt/graphite/webapp/graphite.ini

[uwsgi]

processes = 2

socket = 0.0.0.0:3031

gid = nginx

uid = nginx

chdir = /opt/graphite/webapp/graphite

module = wsgi

buffer-size = 65536

pidfile = /var/run/uwsgi.pid

chmod-socket = 666

pythonpath = /opt/graphite/webapp

daemonize = /var/log/uwsgi.log

4.初始化一些目录,数据目录放在/data1/graphite:

1

2

mkdir -p /data1/graphite/storage/log/webapp/

chown nginx.nginx /data1/graphite/storage/log/webapp/

 

5.配置文件配置见附件。

 

二、使用virtualenv安装graphite:

virtualenv是一个python工具. 它可以创建一个独立的python环境. 这样做的好处是你的python程序运行在这个环境里, 不受其它的 python library的版本问题影响. 比如说centos6默认的python版本是2.6,但是现在python2.6在python核心团队已经不再提供支持,想使用python2.7而不影响其他使用python2.6,就用到了virtualenv。对于后期环境的迁移也很方便。

 

1.首先在centos6.x系统上安装python2.7.x

1)源码安装Python 2.7.x

1

2

3

4

5

6

7

8

# wget http://www.python.org/ftp/python/2.7.8/Python-2.7.8.tar.xz

# xz -d Python-2.7.8.tar.xz

# tar -xvf Python-2.7.8.tar

# cd Python-2.7.8

# 安装在/usr/local下

# ./configure --prefix=/usr/local && make && make altinstall

# /usr/local/bin/python -V

# Python 2.7.8

2.创建virtualenv python2.7环境

1)首先使用easy_install安装virtualenv:

1

# easy_install virtualenv

2)创建python2.7环境到/opt/graphite(由于graphite默认安装在/opt/graphite,方面后期迁移)

1

# virtualenv -p /usr/local/bin/python2.7 /opt/graphite

3.安装graphite:

1)进入到virtualenv环境中:

1

2

# cd /opt/graphite && source ./bin/activate

# (graphite) [root@test123 graphite]#     #这说明已经进入到虚拟环境中。

2)剩下的安装graphite可按照上述使用pip安装graphite进行操作。

 

4.启动graphite:

在virtualenv安装的graphite启动时不必每次都进入到虚拟环境中(cd /opt/graphite && source ./bin/activate)

只需要使用虚拟环境中的python即可,然后它会找到这个python的所有依赖。

1

2

3

# /opt/graphite/bin/python /opt/graphite/bin/carbon-relay.py start

# /opt/graphite/bin/python /opt/graphite/bin/carbon-aggregator.py start

# /opt/graphite/bin/python /opt/graphite/bin/carbon-cache.py --instance=a start

5.环境迁移

以后需要重新创建同样配置的graphite,只需要在新机器上安装上基础环境和virtualenv即可。

然后把原来的创建的虚拟环境/opt/graphite copy过来,修改配置文件即可上线使用。

 

三、使用monit进行监控:

monit是一个用于监视进程、文件、目录和设备等,可以修复停止运作或运作异常的程序,适合处理那些由于多种原因导致的软件错误,用于自动重新启动服务并发送报警。

例如:

1

2

3

4

check process carbon-cache-a whit pidfile /data1/graphite/storage/carbon-cache-a.pid

    start program = "/opt/graphite/bin/python /opt/graphite/bin/carbon-cache.py --instance=a start"

    stop program = "/opt/graphite/bin/python /opt/graphite/bin/carbon-cache.py --instance=a stop"

    if cpu is greater than 90% for 2 cycles then alert

转载于:https://my.oschina.net/mickelfeng/blog/93043

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值