Prometheus, Grafana and Alertmanager 實戰(zhàn)配置

Prometheus時序數(shù)據(jù)庫

系統(tǒng)環(huán)境

[ccli@pek tool]$ cat /etc/redhat-release?

Red Hat Enterprise Linux Server release 7.1 (Maipo)

[ccli@pek tool]$ uname -a

Linux pek 3.10.0-229.1.2.el7.x86_64 #1 SMP Fri Mar 6 17:12:08 EST 2015 x86_64 x86_64 x86_64 GNU/Linux

軟件下載源

https://github.com/prometheus/prometheus/releases/

https://github.com/prometheus/node_exporter/releases

https://grafana.com/grafana/download?platform=linux

https://prometheus.io/download/

Prometheus 部署

下載/安裝

wget https://github.com/prometheus/prometheus/releases/download/v2.7.0/prometheus-2.7.0.linux-amd64.tar.gz

tar zxvf prometheus-2.7.0.linux-amd64.tar.gz

配置

主配置文件ccli.yml

# my global config

global:

? scrape_interval:? ? 15s # Set the scrape interval to every 15 seconds. Default is every 1 minute.

? evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute.

? # scrape_timeout is set to the global default (10s).

# Alertmanager configuration

alerting:

? alertmanagers:

? - static_configs:

? ? - targets:

? ? ? - localhost:9093

# Load rules once and periodically evaluate them according to the global 'evaluation_interval'.

rule_files:

? - "node_down.yml"

? - "memory_over.yml"

? # - "first_rules.yml"

? # - "second_rules.yml"

# A scrape configuration containing exactly one endpoint to scrape:

# Here it's Prometheus itself.

scrape_configs:

? # The job name is added as a label `job=` to any timeseries scraped from this config.

? - job_name: 'prometheus'

? ? # metrics_path defaults to '/metrics'

? ? # scheme defaults to 'http'.

? ? static_configs:

? ? - targets: ['localhost:9090']

? # The job name is added as a label `job=` to any timeseries scraped from this config.

? - job_name: 'testnodeexporter'

? ? # metrics_path defaults to '/metrics'

? ? # scheme defaults to 'http'.

? ? static_configs:

? ? - targets: ['localhost:9100']

Rule Files

node_down.yml

groups:

- name: example

? rules:

? - alert: InstanceDown

? ? expr: up == 0

? ? for: 1m

? ? labels:

? ? ? user: caizh

? ? annotations:

? ? ? summary: "Instance {{ $labels.instance }} down"

? ? ? description: "{{ $labels.instance }} of job {{ $labels.job }} has been down for more than 1 minutes."

memory_over.yml

groups:

- name: example

? rules:

? - alert: NodeMemoryUsage

? ? expr: (node_memory_MemTotal_bytes - (node_memory_MemFree_bytes+node_memory_Buffers_bytes+node_memory_Cached_bytes )) / node_memory_MemTotal_bytes * 100 > 80

? ? for: 1m

? ? labels:

? ? ? user: caizh

? ? annotations:

? ? ? summary: "{{$labels.instance}}: High Memory usage detected"

? ? ? description: "{{$labels.instance}}: Memory usage is above 80% (current value is:{{ $value }})"

Node_exporter 部署

下載/安裝

wget https://github.com/prometheus/node_exporter/releases/download/v0.17.0/node_exporter-0.17.0.linux-amd64.tar.gz

tar zxvf node_exporter-0.17.0.linux-amd64.tar.gz?

Grafana 部署

下載/安裝

wget https://dl.grafana.com/oss/release/grafana-5.4.3.linux-amd64.tar.gz

tar zxvf grafana-5.4.3.linux-amd64.tar.gz

AlertManagement 部署

下載/安裝

wget?https://github.com/prometheus/alertmanager/releases/download/v0.16.0/alertmanager-0.16.0.linux-amd64.tar.gz

tar zxvf alertmanager-0.16.0.linux-amd64.tar.gz?

配置

global:

? smtp_smarthost: 'xxx.email.com:25'

? smtp_from: 'ccli@139.com'

? smtp_auth_username: 'ccli@139.com'

? smtp_auth_password: 'xxxxxx'

? smtp_require_tls: false

route:

? group_by: ['alertname']

? group_interval: 1m

? repeat_interval: 1h

? receiver: live-monitoring

receivers:

- name: 'live-monitoring'

? email_configs:

? - to: 'ccli@139.com'

Alert Mechanism Verification

Start alertmanager

./alertmanager --config.file='test.yml'

Start?prometheus?

./prometheus --config.file='ccli.yml'?

Start?node_exporter

./node_exporter

View Graph

http://192.168.0.224:9090/targets

Get status targets

Click Alerts

Stop?node_exporter

kill node_exporter progress

View Alerts

接收到郵件sample

Draw Grafana Dashboard

Start?prometheus

./prometheus --config.file='ccli.yml'

Start?node_exporter

./node_exporter

Start Grafana

./bin/grafana-server -config conf/defaults.ini

Login Grafana by url?

http://192.168.0.224:3000/

你會進入登錄頁面:

輸入用戶名admin, 密碼admin常侣,會提示是否change password, 選擇skip,進入home Dashboard

點擊Add data source, 如圖:

選擇Prometheus作為數(shù)據(jù)源,輸入prometheus url, here 在192.168.0.224上搭建的 (你可以輸入你自己Prometheus 機器ip),Access選擇Browser, 然后save/test, 因此如圖:

選擇左邊+號添加dashboard, 如圖:

然后點擊添加Graph, 如圖:

然后edit dashboard, 如圖:

Click General Tab, 編輯Panel Titel, enter test_cpu, 如圖:

Click Metrics, 選擇datasouce: Prometheus, query 選擇node_cpu_seconds_total, 然后點擊右上方save按鈕,如圖:

最后命名dashboard,如圖:

對已經(jīng)建好的dashboard,你可以添加更多panel,如圖:

Reference

https://songjiayang.gitbooks.io/prometheus/content/exporter/nodeexporter_query.html

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末咽笼,一起剝皮案震驚了整個濱河市缩赛,隨后出現(xiàn)的幾起案子遮斥,更是在濱河造成了極大的恐慌,老刑警劉巖,帶你破解...
    沈念sama閱讀 217,277評論 6 503
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場離奇詭異结啼,居然都是意外死亡掠剑,警方通過查閱死者的電腦和手機,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 92,689評論 3 393
  • 文/潘曉璐 我一進店門郊愧,熙熙樓的掌柜王于貴愁眉苦臉地迎上來朴译,“玉大人,你說我怎么就攤上這事属铁∶呤伲” “怎么了?”我有些...
    開封第一講書人閱讀 163,624評論 0 353
  • 文/不壞的土叔 我叫張陵焦蘑,是天一觀的道長盯拱。 經(jīng)常有香客問我,道長例嘱,這世上最難降的妖魔是什么狡逢? 我笑而不...
    開封第一講書人閱讀 58,356評論 1 293
  • 正文 為了忘掉前任,我火速辦了婚禮拼卵,結(jié)果婚禮上奢浑,老公的妹妹穿的比我還像新娘。我一直安慰自己间学,他們只是感情好殷费,可當我...
    茶點故事閱讀 67,402評論 6 392
  • 文/花漫 我一把揭開白布印荔。 她就那樣靜靜地躺著,像睡著了一般详羡。 火紅的嫁衣襯著肌膚如雪仍律。 梳的紋絲不亂的頭發(fā)上,一...
    開封第一講書人閱讀 51,292評論 1 301
  • 那天实柠,我揣著相機與錄音水泉,去河邊找鬼。 笑死窒盐,一個胖子當著我的面吹牛草则,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播蟹漓,決...
    沈念sama閱讀 40,135評論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼炕横,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了葡粒?” 一聲冷哼從身側(cè)響起份殿,我...
    開封第一講書人閱讀 38,992評論 0 275
  • 序言:老撾萬榮一對情侶失蹤,失蹤者是張志新(化名)和其女友劉穎嗽交,沒想到半個月后卿嘲,有當?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 45,429評論 1 314
  • 正文 獨居荒郊野嶺守林人離奇死亡夫壁,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 37,636評論 3 334
  • 正文 我和宋清朗相戀三年拾枣,在試婚紗的時候發(fā)現(xiàn)自己被綠了。 大學時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片盒让。...
    茶點故事閱讀 39,785評論 1 348
  • 序言:一個原本活蹦亂跳的男人離奇死亡梅肤,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出糯彬,到底是詐尸還是另有隱情凭语,我是刑警寧澤葱她,帶...
    沈念sama閱讀 35,492評論 5 345
  • 正文 年R本政府宣布撩扒,位于F島的核電站,受9級特大地震影響吨些,放射性物質(zhì)發(fā)生泄漏搓谆。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點故事閱讀 41,092評論 3 328
  • 文/蒙蒙 一豪墅、第九天 我趴在偏房一處隱蔽的房頂上張望泉手。 院中可真熱鬧,春花似錦偶器、人聲如沸斩萌。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,723評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽颊郎。三九已至憋飞,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間姆吭,已是汗流浹背榛做。 一陣腳步聲響...
    開封第一講書人閱讀 32,858評論 1 269
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留内狸,地道東北人检眯。 一個月前我還...
    沈念sama閱讀 47,891評論 2 370
  • 正文 我出身青樓,卻偏偏與公主長得像昆淡,于是被迫代替她去往敵國和親锰瘸。 傳聞我的和親對象是個殘疾皇子,可洞房花燭夜當晚...
    茶點故事閱讀 44,713評論 2 354

推薦閱讀更多精彩內(nèi)容

  • 文章目的: 1昂灵、向沒聽過或者剛聽過但是還對這個監(jiān)控系統(tǒng)沒有任何概念的開發(fā)者介紹Prometheus的應用場景获茬。2、...
    whaike閱讀 39,627評論 15 59
  • 1.grafana安裝 sudo yum install https://s3-us-west-2.amazona...
    念之森蘭閱讀 1,143評論 0 4
  • Prometheus TSDB是什么倔既? (Time Series Database) 簡單的理解為.一個優(yōu)化后用來...
    ilkkzm閱讀 19,234評論 0 4
  • 這篇影評包含劇透恕曲,慎入!如果你已經(jīng)看完了電影渤涌,希望能讓你有所收獲佩谣。 這部電影注定是不適合一部分人的,對于他們電影可...
    glfrx閱讀 475評論 1 4
  • 下班坐在地鐵上实蓬、回憶一下我的工地時候茸俭。2016年參加了國家一級建造師的資格考試、難度可想而知…考試完安皱、還是乖乖的跑...
    破郵筒閱讀 13,731評論 37 29