如何解析MySQLprometheus郵件報警配置

這篇文章給大家介紹prometheus如何配置MySQL郵件報警,內(nèi)容非常詳細,感興趣的小伙伴們可以參考借鑒,希望對大家能有所幫助。

10年積累的網(wǎng)站設(shè)計、做網(wǎng)站經(jīng)驗,可以快速應(yīng)對客戶對網(wǎng)站的新想法和需求。提供各種問題對應(yīng)的解決方案。讓選擇我們的客戶得到更好、更有力的網(wǎng)絡(luò)服務(wù)。我雖然不認識你,你也不認識我。但先網(wǎng)站設(shè)計后付款的網(wǎng)站建設(shè)流程,更有平泉免費網(wǎng)站建設(shè)讓你可以放心的選擇與我們合作。

這里介紹一下prometheus的郵件報警配置。

alertmanager下載

prometheus報警配置需要用到alertmanager組件,這個組件可以到prometheus官網(wǎng)上進行下載。

https://prometheus.io/download/

如何解析MySQL prometheus郵件報警配置

由于最新版本的alertmanager組件配置郵箱通訊存在一些問題,我們這里選擇在github上下載0.14版本的alertmanager。

https://github.com/prometheus/alertmanager

如何解析MySQL prometheus郵件報警配置

附具體下載地址:

https://github.com/prometheus/alertmanager/releases/download/v0.14.0/alertmanager-0.14.0.linux-amd64.tar.gz

alertmanager安裝配置

將下載的alertmanager包進行解壓安裝。

tar -xf alertmanager-0.14.0.linux-amd64.tar.gz
mv alertmanager-0.14.0.linux-amd64 /data/alertmanager

編輯alertmanager的配置文件,添加郵箱信息。

# cd /data/alertmanager
# cat alertmanager.yml
global:
  smtp_smarthost: smtp.exmail.xxx.com:465 # 發(fā)件人郵箱smtp地址
  smtp_auth_username: xxxx@xxx.com # 發(fā)件人郵箱賬號
  smtp_from: xxx@xxx.com # 發(fā)件人郵箱賬號
  smtp_auth_password: xxxxxx # 發(fā)件人郵箱密碼
  resolve_timeout: 5m
  smtp_require_tls: false
route:
  # group_by: ['alertname'] # 報警分組依據(jù)
  group_wait: 10s # 最初即第一次等待多久時間發(fā)送一組警報的通知
  group_interval: 10s # 在發(fā)送新警報前的等待時間
  repeat_interval: 1m # 發(fā)送重復(fù)警報的周期 對于email配置中多頻繁
  receiver: 'email'
receivers:
- name: email
  email_configs:
  - send_resolved: true
    to: xxx@xxx.com # 收件人郵箱賬號

啟動alertmanager。

# cd /data/alertmanager
./alertmanager --config.file=alertmanager.yml &

alertmanager的默認端口為9093。

如何解析MySQL prometheus郵件報警配置

prometheus配置

在prometheus目錄下編輯報警模版alert_rules.yml,添加一些自定義報警項。

# cd /data/prometheus
# cat alert_rules.yml
groups:
- name: MySQL-rules
  rules:
  - alert: MySQL Status # 告警名稱
    expr: up == 0
    for: 5s # 滿足告警條件持續(xù)時間多久后,才會發(fā)送告警
    annotations: # 解析項,詳細解釋告警信息
      summary: "{{$labels.instance}}: MySQL has stop !!!"
      value: "{{$value}}"
      alertname: "MySQL數(shù)據(jù)庫停止運行"
      description: "檢測MySQL數(shù)據(jù)庫運行狀態(tài)"
      message: 當(dāng)前數(shù)據(jù)庫實例{{$labels.instance}}已經(jīng)停止運行,請及時處理
  - alert: MySQL Slave IO Thread Status # 告警名稱
    expr: mysql_slave_status_slave_io_running == 0
    for: 5s # 滿足告警條件持續(xù)時間多久后,才會發(fā)送告警
    annotations: # 解析項,詳細解釋告警信息
      summary: "{{$labels.instance}}: MySQL Slave IO Thread has stop !!!"
      value: "{{$value}}"
      alertname: "MySQL主從IO線程停止運行"
      description: "檢測MySQL主從IO線程運行狀態(tài)"
      message: 當(dāng)前數(shù)據(jù)庫實例{{$labels.instance}} IO線程已經(jīng)停止運行,請及時處理
  - alert: MySQL Slave SQL Thread Status # 告警名稱
    expr: mysql_slave_status_slave_sql_running == 0
    for: 5s # 滿足告警條件持續(xù)時間多久后,才會發(fā)送告警
    annotations: # 解析項,詳細解釋告警信息
      summary: "{{$labels.instance}}: MySQL Slave SQL Thread has stop !!!"
      value: "{{$value}}"
      alertname: "MySQL主從SQL線程停止運行"
      description: "檢測MySQL主從SQL線程運行狀態(tài)"
      message: 當(dāng)前數(shù)據(jù)庫實例{{$labels.instance}} SQL線程已經(jīng)停止運行,請及時處理
  - alert: MySQL Slave Delay Status # 告警名稱
    expr: mysql_slave_status_sql_delay == 30
    for: 5s # 滿足告警條件持續(xù)時間多久后,才會發(fā)送告警
    annotations: # 解析項,詳細解釋告警信息
      summary: "{{$labels.instance}}: MySQL Slave Delay has more than 30s !!!"
      value: "{{$value}}"
      alertname: "MySQL主從延時過大"
      description: "檢測MySQL主從延時狀態(tài)"
      message: 當(dāng)前數(shù)據(jù)庫實例{{$labels.instance}} 主從延時狀態(tài)已經(jīng)超過30s,請及時處理

在prometheus目錄下編輯prometheus的配置文件,將監(jiān)控的配置信息添加到prometheus.yml。

# cd /data/prometheus
# cat prometheus.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:
      - 172.18.0.24:9093 # 對應(yīng)啟動的altermanager節(jié)點的9093端口
# Load rules once and periodically evaluate them according to the global 'evaluation_interval'.
rule_files:
  - "alert_rules.yml" # 對應(yīng)前面編輯的報警模版alert_rules.yml文件
# A scrape configuration containing exactly one endpoint to scrape:
scrape_configs:
  - file_sd_configs:
    - files:
      - mysql.yml
    job_name: MySQL
    metrics_path: /metrics
    relabel_configs:
    - source_labels: [__address__]
      regex: (.*)
      target_label: __address__
      replacement: $1

編輯完成后,重新加載一下配置更改。

kill -HUP [prometheus PID]

驗證郵件報警

登陸prometheus的web頁面,查看報警信息。

瀏覽器輸入Prometheus_IP:9090 ,可以看到各個報警項的狀態(tài)。

如何解析MySQL prometheus郵件報警配置

停掉主從線程,模擬觸發(fā)報警。

如何解析MySQL prometheus郵件報警配置

Slave SQL線程停掉后,報警項顏色變成黃色,持續(xù)時間超過定義的持續(xù)時間后,顏色變紅,并發(fā)送郵件。

如何解析MySQL prometheus郵件報警配置

如何解析MySQL prometheus郵件報警配置

收到報警郵件。

如何解析MySQL prometheus郵件報警配置

如何解析MySQL prometheus郵件報警配置

關(guān)于prometheus如何配置MySQL郵件報警就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,可以學(xué)到更多知識。如果覺得文章不錯,可以把它分享出去讓更多的人看到。

本文標題:如何解析MySQLprometheus郵件報警配置
文章鏈接:http://muchs.cn/article46/gedceg.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供品牌網(wǎng)站設(shè)計、網(wǎng)站設(shè)計Google、網(wǎng)站制作、小程序開發(fā)、做網(wǎng)站

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

h5響應(yīng)式網(wǎng)站建設(shè)