這篇文章給大家介紹prometheus如何配置MySQL郵件報(bào)警,內(nèi)容非常詳細(xì),感興趣的小伙伴們可以參考借鑒,希望對(duì)大家能有所幫助。
創(chuàng)新互聯(lián)技術(shù)團(tuán)隊(duì)十多年來致力于為客戶提供成都網(wǎng)站建設(shè)、網(wǎng)站設(shè)計(jì)、成都品牌網(wǎng)站建設(shè)、網(wǎng)絡(luò)營(yíng)銷推廣、搜索引擎SEO優(yōu)化等服務(wù)。經(jīng)過多年發(fā)展,公司擁有經(jīng)驗(yàn)豐富的技術(shù)團(tuán)隊(duì),先后服務(wù)、推廣了上千家網(wǎng)站,包括各類中小企業(yè)、企事單位、高校等機(jī)構(gòu)單位。這里介紹一下prometheus的郵件報(bào)警配置。
alertmanager下載
prometheus報(bào)警配置需要用到alertmanager組件,這個(gè)組件可以到prometheus官網(wǎng)上進(jìn)行下載。
https://prometheus.io/download/
由于最新版本的alertmanager組件配置郵箱通訊存在一些問題,我們這里選擇在github上下載0.14版本的alertmanager。
https://github.com/prometheus/alertmanager
附具體下載地址:
https://github.com/prometheus/alertmanager/releases/download/v0.14.0/alertmanager-0.14.0.linux-amd64.tar.gz
alertmanager安裝配置
將下載的alertmanager包進(jìn)行解壓安裝。
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ā)件人郵箱賬號(hào) smtp_from: xxx@xxx.com # 發(fā)件人郵箱賬號(hào) smtp_auth_password: xxxxxx # 發(fā)件人郵箱密碼 resolve_timeout: 5m smtp_require_tls: false route: # group_by: ['alertname'] # 報(bào)警分組依據(jù) group_wait: 10s # 最初即第一次等待多久時(shí)間發(fā)送一組警報(bào)的通知 group_interval: 10s # 在發(fā)送新警報(bào)前的等待時(shí)間 repeat_interval: 1m # 發(fā)送重復(fù)警報(bào)的周期 對(duì)于email配置中多頻繁 receiver: 'email' receivers: - name: email email_configs: - send_resolved: true to: xxx@xxx.com # 收件人郵箱賬號(hào)
啟動(dòng)alertmanager。
# cd /data/alertmanager ./alertmanager --config.file=alertmanager.yml &
alertmanager的默認(rèn)端口為9093。
prometheus配置
# cd /data/prometheus # cat alert_rules.yml groups: - name: MySQL-rules rules: - alert: MySQL Status # 告警名稱 expr: up == 0 for: 5s # 滿足告警條件持續(xù)時(shí)間多久后,才會(huì)發(fā)送告警 annotations: # 解析項(xiàng),詳細(xì)解釋告警信息 summary: "{{$labels.instance}}: MySQL has stop !!!" value: "{{$value}}" alertname: "MySQL數(shù)據(jù)庫停止運(yùn)行" description: "檢測(cè)MySQL數(shù)據(jù)庫運(yùn)行狀態(tài)" message: 當(dāng)前數(shù)據(jù)庫實(shí)例{{$labels.instance}}已經(jīng)停止運(yùn)行,請(qǐng)及時(shí)處理 - alert: MySQL Slave IO Thread Status # 告警名稱 expr: mysql_slave_status_slave_io_running == 0 for: 5s # 滿足告警條件持續(xù)時(shí)間多久后,才會(huì)發(fā)送告警 annotations: # 解析項(xiàng),詳細(xì)解釋告警信息 summary: "{{$labels.instance}}: MySQL Slave IO Thread has stop !!!" value: "{{$value}}" alertname: "MySQL主從IO線程停止運(yùn)行" description: "檢測(cè)MySQL主從IO線程運(yùn)行狀態(tài)" message: 當(dāng)前數(shù)據(jù)庫實(shí)例{{$labels.instance}} IO線程已經(jīng)停止運(yùn)行,請(qǐng)及時(shí)處理 - alert: MySQL Slave SQL Thread Status # 告警名稱 expr: mysql_slave_status_slave_sql_running == 0 for: 5s # 滿足告警條件持續(xù)時(shí)間多久后,才會(huì)發(fā)送告警 annotations: # 解析項(xiàng),詳細(xì)解釋告警信息 summary: "{{$labels.instance}}: MySQL Slave SQL Thread has stop !!!" value: "{{$value}}" alertname: "MySQL主從SQL線程停止運(yùn)行" description: "檢測(cè)MySQL主從SQL線程運(yùn)行狀態(tài)" message: 當(dāng)前數(shù)據(jù)庫實(shí)例{{$labels.instance}} SQL線程已經(jīng)停止運(yùn)行,請(qǐng)及時(shí)處理 - alert: MySQL Slave Delay Status # 告警名稱 expr: mysql_slave_status_sql_delay == 30 for: 5s # 滿足告警條件持續(xù)時(shí)間多久后,才會(huì)發(fā)送告警 annotations: # 解析項(xiàng),詳細(xì)解釋告警信息 summary: "{{$labels.instance}}: MySQL Slave Delay has more than 30s !!!" value: "{{$value}}" alertname: "MySQL主從延時(shí)過大" description: "檢測(cè)MySQL主從延時(shí)狀態(tài)" message: 當(dāng)前數(shù)據(jù)庫實(shí)例{{$labels.instance}} 主從延時(shí)狀態(tài)已經(jīng)超過30s,請(qǐng)及時(shí)處理
在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 # 對(duì)應(yīng)啟動(dòng)的altermanager節(jié)點(diǎn)的9093端口 # Load rules once and periodically evaluate them according to the global 'evaluation_interval'. rule_files: - "alert_rules.yml" # 對(duì)應(yīng)前面編輯的報(bào)警模版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]
驗(yàn)證郵件報(bào)警
登陸prometheus的web頁面,查看報(bào)警信息。
瀏覽器輸入Prometheus_IP:9090 ,可以看到各個(gè)報(bào)警項(xiàng)的狀態(tài)。
停掉主從線程,模擬觸發(fā)報(bào)警。
Slave SQL線程停掉后,報(bào)警項(xiàng)顏色變成黃色,持續(xù)時(shí)間超過定義的持續(xù)時(shí)間后,顏色變紅,并發(fā)送郵件。
收到報(bào)警郵件。
關(guān)于prometheus如何配置MySQL郵件報(bào)警就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,可以學(xué)到更多知識(shí)。如果覺得文章不錯(cuò),可以把它分享出去讓更多的人看到。
當(dāng)前題目:如何解析MySQLprometheus郵件報(bào)警配置-創(chuàng)新互聯(lián)
網(wǎng)站網(wǎng)址:http://bm7419.com/article26/gdccg.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供面包屑導(dǎo)航、動(dòng)態(tài)網(wǎng)站、用戶體驗(yàn)、云服務(wù)器、搜索引擎優(yōu)化、網(wǎng)站建設(shè)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容