一、Grafana安裝和啟動
Grafana支持查詢Prometheus。從Grafana 2.5.0(2015-10-28)開始包含Prometheus的Grafana數據源。
[root@prometheus ~]# wget https://dl.grafana.com/oss/release/grafana-6.5.2-1.x86_64.rpm
[root@prometheus ~]# yum localinstall grafana-6.5.2-1.x86_64.rpm -y
[root@prometheus ~]# systemctl enable grafana
[root@prometheus ~]# systemctl start grafana
[root@prometheus ~]# netstat -tulnp |grep 3000
tcp6 0 0 :::3000 :::* LISTEN 34336/grafana-serve
默認情況下,Grafana將在http://localhost:3000上監聽 。默認登錄名是“ admin” /“ admin”,首次登陸提示修改密碼,可以skip(跳過)。
二、配置數據源
創建Prometheus數據源:
- 單擊Grafana LOGO以打開側邊欄菜單。
- 單擊邊欄中的“Datasource”。
- 選擇“Prometheus”。
- 填寫Prometheus服務器網址(例如,http://localhost:9090/)
- 根據需要調整其他數據源設置(例如,關閉代理訪問)。
- 點擊“Save&Test”以保存新的數據源。
三、配置dashboard
配置dashboard有兩種方式,一種是自定義編輯增加各種指標,一種是通過官網上大佬搞出來的dashboard模板加載,這里加載了第二種方式。另外在增加dashboard的時候會自動添加prometheus本身的監控模板,添加完成后,可以看到prometheus server的各種資源指標,如圖:
官方模板地址:https://grafana.com/grafana/dashboards,在官方搜索模板后,填入模板id,導入如圖:
增加完成后,重新點開模板,這里使用了id:8919的模板,非常炫酷,如圖:
四、配置grafana告警
首先配置grafana的smtp,保證郵件服務的支持:
[root@prometheus alertmanager]# vim /etc/grafana/grafana.ini
...
[smtp]
enabled = true
host = smtp.qq.com:25
user = xxxxxxxxx@qq.com
# If the password contains # or ; you have to wrap it with trippel quotes. Ex """#password;"""
password = nqiscvqgbtjrcaid
;cert_file =
;key_file =
skip_verify = true
from_address = xxxxxxxxx@qq.com
from_name = Grafana
...
[root@prometheus alertmanager]# /etc/init.d/grafana-server restart
Restarting grafana-server (via systemctl): [ OK ]
增加一個演示的dashboard,並配置CPU告警,這里需要配置數據源,以及metrics,metrics是直接prometheus上的查詢語句出來的指標值,如圖:
而后配置grafana 中的alert告警配置,填寫通知方式:
當CPU負載超過我們配置的閾值后,會收到告警信息,如圖: