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:

#easy_install pip

3)安裝graphite依賴的一些python包:

     pip install -r requirements.txt

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

[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.

[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:

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

# 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:

# easy_install virtualenv

2)創建python2.7環境到/opt/graphite(由於graphite默認安裝在/opt/graphite,方面後期遷移)

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


3.安裝graphite:

1)進入到virtualenv環境中:

# 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的所有依賴。

# /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是一個用於監視進程、文件、目錄和設備等,可以修復停止運作或運作異常的程序,適合處理那些由於多種原因導致的軟件錯誤,用於自動重新啓動服務併發送報警。

例如:

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


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章