grafana 配置 prometheus 告警(五)

Email configuration

咱們這裏選擇 email 告警,首先修改 grafana 的配置文件 /etc/grafana/grafana.ini,找到 SMTP 部分,修改成以下:node

[smtp]
;enabled = false
enabled = true
;host = localhost:25
host = smtp.exmail.qq.com:25
;user =
user = notice@wzlinux.com
# If the password contains # or ; you have to wrap it with triple quotes. Ex """#password;"""
;password =
password = Q7P1hsdfsenzzyM
;cert_file =
;key_file =
;skip_verify = false
;from_address = admin@grafana.localhost
from_address = notice@wzlinux.com
from_name = Grafana
# EHLO identity in SMTP dialog (defaults to instance_name)
;ehlo_identity = dashboard.example.com

修改完成後,重啓 grafana。linux

Notification channels

登錄到 grafana 中,建立一個通知渠道,測試一下,看看是否收到郵件。sql

image-20200524211203445

  • Name - Enter a name for this channel. It will be displayed when users add notifications to alert rules.
  • Type - Select the channel type. Refer to the List of supported notifiers for details.
  • Default (send on all alerts) - When selected, this option sends a notification on this channel for all alert rules.
  • Include Image - See Enable images in notifications for details.
  • Disable Resolve Message - When selected, this option disables the resolve message [OK] that is sent when the alerting state returns to false.
  • Send reminders - When this option is checked additional notifications (reminders) will be sent for triggered alerts. You can specify how often reminders should be sent using number of seconds (s), minutes (m) or hours (h), for example 30s, 3m, 5m or 1h.

Create alerts

grafana 不支持帶有變量的模板報警,因此咱們須要建立一個不帶有變量的模板,這個咱們能夠去官方的 dashboard 中找一個,我這裏找到編號爲5984,你們能夠安裝這個模板。ide

image-20200524211617663

我在裏面簡單修改了一下格式,以及數據源,主要是針對 CPU 的負載修改了一下,其餘資源默承認以使用。測試

image-20200524211731861

我這邊已經測試過了,沒有什麼問題,報警均可以正常運行,我把 promSQL 貼出來this

CPU:

100 - (avg by (instance) (irate(node_cpu_seconds_total{mode="idle"}[5m])) * 100)

legend 設置爲{{instance}}3d

內存:

100*(node_memory_MemTotal_bytes - node_memory_MemFree_bytes - node_memory_Buffers_bytes - node_memory_Cached_bytes) / node_memory_MemTotal_bytes

legend 設置爲{{instance}}code

存儲:

100.0 - 100 * ((node_filesystem_avail_bytes / 1000 / 1000 ) / (node_filesystem_size_bytes  / 1024 / 1024))

legend 設置爲 {{instance}} - {{mountpoint}}blog

案例

如下拿 CPU 的配置截圖給你們看下:ip

Queries:

image-20200525142217564

Visualization:

image-20200525142329210

Alert:

image-20200525142405887

歡迎你們掃碼關注,獲取更多信息

grafana 配置 prometheus 告警(五)

相關文章
相關標籤/搜索