歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> 關於Linux >> Ubuntu14.04安裝圖形監控工具Graphite

Ubuntu14.04安裝圖形監控工具Graphite

日期:2017/3/1 12:26:43   编辑:關於Linux

什麼是graphite?

先看看百度百科是怎麼介紹

Graphite 是一個Python寫的web應用,采用django框架,Graphite用來進行收集服務器所有的即時狀態,用戶請求信息,Memcached命中率,RabbitMQ消息服務器的狀態,Unix操作系統的負載狀態,Graphite服務器大約每分鐘需要有4800次更新操作,Graphite采用簡單的文本協議和繪圖功能可以方便地使用在任何操作系統上。

百度百科講的還算是比較清楚了,Graphite是用來監控系統的, 比如操作系統,緩存服務系統等,但是監控的數據怎麼得到呢?Graphite並不負責,它只負責顯示,數據哪裡來人家不care,你只要按照他的數據格式給它,Graphite就可以機智的用漂亮的頁面顯示給你,不過不用擔心,graphite的安裝的一系列套件,提供了API去傳數據給它,而且數據如何存儲的也不用我們擔心,只管發數據給它就行。說的這麼好,到底怎麼安裝呢?

先別急,事情總不是那麼完美,Graphite不支持windows,因此對於只使用Windows的Coder就有點小失落了,不過沒關系,相信作為程序員都是有辦法的,這些都是小事情。

下面就進入Graphite的世界!

安裝

操作系統:Ubuntu 14.04
Python :2.7.6

安裝graphite的環境

Graphite的需要的支持環境如下:
* a UNIX-like Operating System
* Python 2.6 or greater
* Pycairo
* Django 1.4 or greater
* django-tagging 0.3.1 or greater
* Twisted 8.0 or greater (10.0+ recommended)
* zope-interface (often included in Twisted package dependency)
* pytz
* fontconfig and at least one font package (a system package usually)
* A WSGI server and web server. Popular choices are:
* Apache with mod_wsgi
* gunicorn with nginx
* uWSGI with nginx

Ubuntu已經安裝了python,所以不需要安裝再安裝了,只用確保版本大於等於2.6即可。這裡我們服務器選擇Apache,如果已經安裝了就不用安裝了,只用安裝WSGI的模塊libapache2-mod-wsgi。
下面是安裝所有支持環境的命令,建議一個一個安裝,可以查看每個安裝成功與否。

$sudo apt-get update
$ sudo apt-get install apache2 libapache2-mod-wsgi python-django python-twisted python-cairo python-pip python-django-tagging

安裝Graphite三大組件

whisper(數據庫) carbon(監控數據,默認端口2003,外部程序StatsD通過這個端口,向Graphite輸送采樣的數據) graphite-web(網頁UI)

使用pip命令可以快速的安裝

$sudo pip install whisper
$sudo pip install carbon
$sudo pip install graphite-web

安裝完成後默認在/opt/graphite目錄

然後使用Pip安裝pytz,用於轉換TIME_ZONE,後面會介紹

$ sudo pip install pytz

配置graphite

進入/opt/graphite/conf目錄,使用給的example配置

$ sudo cp carbon.conf.example carbon.conf 
$ sudo cp storage-schemas.conf.example storage-schemas.conf 
$ sudo cp graphite.wsgi.example graphite.wsgi  

為apache添加Graphite的虛擬主機

安裝graphite的時候會生成一個/opt/graphite/example的文件夾,裡面有一個配置好的虛擬主機文件,將其復制到Apache放置虛擬主機的配置文件的地方,默認是/etc/apache2/sites-available文件夾

$sudo cp /opt/graphite/example/example-graphite-vhost.conf    /etc/apache2/sites-available/graphite-vhost.conf

然後在編輯修改監聽端口為8008以及一個WSGISocketPrefix的默認目錄,修改後如下:

\<喎?/kf/ware/vc/" target="_blank" class="keylink">vcD4NCjxwPjxjb2RlIGNsYXNzPQ=="hljs lasso">/etc/apache2/sites-enable下建立該配置文件的軟鏈接

$cd /etc/apache2/sites-enable
$sudo ln -s ../sites-available/graphite-vhost.conf   graphite-vhost.conf 

初始化數據庫

初始化 graphite需要的數據庫,修改 storage 的權限,用拷貝的方式創建 local_settings.py文件(中間會問你是不是要創建一個superuser,選擇no,把<用戶名>改成你當前的Ubuntu的用戶名,這是為了讓carbon有權限寫入whisper數據庫,其實carbon裡面也可以指定用戶的,更新:graphite需要admin權限的用戶才能創建User Graph,所以superuser是很重要的,可以使用 python manage.py createsuperuser創建):

$ cd /opt/graphite/webapp/graphite/

$ sudo python manage.py syncdb
$ sudo chown -R <用戶名>:<用戶名> /opt/graphite/storage/  
$ sudo cp local_settings.py.example local_settings.py

$ sudo /etc/init.d/apache2 restart  #重啟apache

上面代碼中的用戶名為Apache對應的用戶,一般為www-data,可以使用下面的代碼獲得,在apache的web根目錄(默認:var/www/html)穿件control.php

在浏覽器訪問http://localhost/control.php既可以看到對應的用戶名

啟動Carbon

$ cd /opt/graphite/

$ sudo ./bin/carbon-cache.py start

此時在浏覽器訪問http://localhost:8008,看到下面頁面說明配置成功

\

如果出現沒有權限訪問的錯誤頁面,可以修改Apache配置文件/etc/pache2/apache2.conf,找到下圖中的位置,注釋掉Require all denied ,然後重啟Apache再次訪問。

\

修改Graphite默認的時區

打開/opt/graphite/webapp/graphite/setting.py,找到TIME_ZONE,默認是UTC,將其修改為Asia/Shanghai
,然後找到USE_TZ,沒有的話自己在文件末尾添加,設置為True

發送數據到graphite

發送數據的方法比較多,科一參考官方文檔Feeding In Your Data,此外,在/opt/graphite/examples下提供了一份通過Socket發送數據的例子examples-client.py

Copyright © Linux教程網 All Rights Reserved