用graphite diamond做監控

2021-06-28 00:43:48 字數 4207 閱讀 2027

開局先貼兩個文章,值得一讀

很讚的blog

另一篇介紹graphite的文章

無論是什麼系統,只要上線,就需要運維,這時候很想看一些監控的圖表,graphite就很方便的實現了這個需求。

而graphite採用metrics的方式,又有很多其他的tool為他做支援,所監控的不僅僅是機器的一些東西,你可以監控你爬蟲的指標,

log的info,error頻次,nginx**的訪問數量等等,基本是你需要監控什麼,很容易的就可以做到。

我從2023年初就在自己的todolist新增了要玩graphite, 陸續玩了3、4次都失敗了,原因都是安裝裡面某些步驟失敗,

這兩天終於搞成功了,寫個部落格記錄一下。

graphite-web 大部分的安裝方式比較簡單,都是用pip就可以安裝,但是裝完後有個坑,

文件中說使用pip install graphite-web,但是pip中的graphite-web太老了,

導致有個cairo,庫在ubuntu下打死也裝不上,在新的原始碼中此bug已經修復。我已經提了issue 1004

因為用的graphite-index,直接拿了他的幾張圖來看最終效果

我用的是ubuntu, 寫在最上面, 並且我假設你了解基本的python語法,用過pip, virtualenv, 沒用過也沒問題。

文件需要翻牆,因此貼出主要的安裝步驟.

最好安裝到python的virtualenv中,具體virtualenv的使用可以參考這裡

首先,檢視graphite-web的requirements.txt,發現需要裝一些系統的庫,sudo apt-get install libcairo2-dev

pip install 

pip install whisper

pip install carbon

pip install graphite-web

這裡我先貼下最終整個系統搭起來後的各個python庫版本, 其中logster是乙個做日誌監控的東西,先git clone的本機,然後pip install -e logster專案位址即可

django==1.4.8

twisted==11.1.0

argparse==1.2.1

astroid==1.2.1

cairocffi==0.6

ceres==0.10.0

cffi==0.8.6

configobj==5.0.6

diamond==3.5.0

django-tagging==0.3.3

ipython==2.3.0

logilab-common==0.62.1

-e git+

mock==1.0.1

psutil==2.1.3

pycparser==2.10

pylint==1.3.1

pylint-django==0.5.5

pylint-plugin-utils==0.2.2

pyparsing==1.5.7

python-memcached==1.47

******json==2.1.6

six==1.8.0

txamqp==0.4

whisper==0.9.12

wsgiref==0.1.2

zope.inte***ce==4.1.1

根據文件的步驟安裝完成後,你會發現/opt/graphite下多了一堆東西,將/opt/graphite/conf下的*.example,拷貝到去掉example即可

graphite有個服務在2003,2004介面上,你的metrics需要扔到2003上,具體請看文件,現在不用在意這些細節。

metrics就是類似這樣的字串 字首.字首.字首....... blabala, graphite就是根據這種東西畫圖的,具體請看文件,不用在意這些細節,

因為其他的工具都有封裝。

*. 啟動carbon, metrics會扔到carbon這個小屋裡面

/opt/graphite/bin/carbon-cache.py start
*. 製造一些metrics, 更改host,或者server, 這裡只是做測試,之後會用diamond來採集metrics

vim /etc/hosts

新增 127.0.0.1 graphite, 或者其他的東西

python /opt/graphite/examples/example-client.py

這些資料存在 /opt/graphite/storage/whisper, 嘗試修改example-client.py發點不一樣的東西

*. 配置並修改graphite-web的幾行**,啟動這個django專案

找到import cairo, ....(這就是坑)

改為import ...

try:

import cairo

except importerror:

import cairocffi as cairo

啟動django

瀏覽器開啟 這兩個頁面玩一下,你會看到左側tree那邊有一些資料

這些資料存在/opt/graphite/storage/whisper給graphite填資料的方式太多了,這裡使用diamond,因為豆瓣有一層graphite+diamond的皮, 下面會說

git clone 

cd diamond

pip install -e ./

cp /etc/diamond/diamond.conf

vim /etc/diamond/diamond.conf

找到host, host = graphite(還記得之前配的host麼)

檢視下這個檔案,你可以cd到collectors_path, handlers_path去看看裡面的檔案, 因為定製自己的

diamand collector時需要根據這些東西來寫(繼承collector,重寫collect方法),此篇不談

service diamond restart

graphite的介面實在是不敢恭維,因此很多人為它寫ui,這裡選擇豆瓣的graphite-index

選擇它是因為配置簡單

git clone 

cd graph-index

vim config.py

graphite_url天上你graphite的ip已經埠

graphite_url = ''

./update-metrics.py

crontab -e

*/5 * * * * python 絕對路徑到/update-metrics.py

./graph-index.py

安裝:

git clone [email protected]:duoduo369/logster.git

cd logster

pip install -e ./

用法:

logster --output=graphite --graphite-host=graphite的ip已經埠 你的parser 日誌絕對路徑

logster --output=graphite --graphite-host=127.0.0.1:2003 pythonlogster /var/log/adx/adxsterr.log

如果你需要自己定製parser,參照logster/logster/parsers下的東西寫乙個就好。

因為logster自帶向graphite發metrics,無須向diamond整合(寫collector),只要起乙個定時任務即可。

當然,如果你熟悉django,可以把graphite, graphite-index人給gunicorn和supervisor,這不是重點,需要的可以參考我github上的demo.

至於定製你的diamond collector,監控你想監控的東西,請自己翻閱文件 (繼承collector,重寫collect方法),將寫好的collector放在collectors_path下.

用Margin還是用Padding

用margin還是用padding 何時應當使用margin 需要在border外側新增空白時。空白處不需要背景 色 時。上下相連的兩個盒子之間的空白,需要相互抵消時。如15px 20px的margin,將得到20px的空白。何時應當時用padding 需要在border內測新增空白時。空白處需要背...

用Margin還是用Padding

用margin還是用padding這個問題是每個學習css高階時的必經之路。css邊距屬性定義元素周圍的空間。通過使用單獨的屬性,可以對上 右 下 左的外邊距進行設定。也可以使用簡寫的外邊距屬性同時改變所有的外邊距。w3school 邊界 margin 元素周圍生成額外的空白區。空白區 通常是指其他...

用yaml寫用例

第一步 安裝yaml,在執行裡輸入 pip install pyyaml 檢驗是否安裝成功,在pycharm裡輸入 import yaml 第二步 建立乙個file,字尾寫yaml或yml 在yml檔案裡寫入單個使用者名稱和密碼 開啟yml檔案並以字典的形式列印出來 執行結果 在yml檔案裡寫入多個...