prometheus告警

下載好altermanager之后,我們解壓。其中的altermanager.yml是altermanager的配置文件。主要用來(lái)管理告警信息發(fā)送的規(guī)則,也就是說(shuō)給誰(shuí)發(fā),用那種方式。

這塊作者簡(jiǎn)單測(cè)試了一下監(jiān)控mysql的線程數(shù)的告警。首先配置一下prometheus的數(shù)據(jù)收集的規(guī)則和push告警信息的地址。

groups:- name: test-mysql-rulerules:- alert: "連接數(shù)報(bào)警"expr: mysql_global_variables_mysqlx_max_connections > 90 #連接數(shù)大于90就告警for: 1slabels:severity: warningannotations:summary: "服務(wù)名:{{$labels.alertname}}"description: "業(yè)務(wù)msyql連接數(shù)不夠報(bào)警: 當(dāng)前值為:{{ $value }}"value: "{{ $value }}"
在prometheus配置文件中添加這個(gè)告警規(guī)則
# my global configglobal: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 configurationalerting:alertmanagers:- static_configs:- targets: ["localhost:9093"] #發(fā)送到altermanager的告警分析中# Load rules once and periodically evaluate them according to the global 'evaluation_interval'.rule_files:- "tianjingle_rules.yml"# 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'static_configs:- targets: ['localhost:9090']# 添加msyql的監(jiān)控- job_name: 'mysql'# 靜態(tài)添加nodestatic_configs:# 指定監(jiān)控端- targets: ['localhost:9104']- job_name: 'bounter-monitor'scrape_interval: 5smetrics_path: '/actuator/prometheus'static_configs:- targets: ['localhost:8081']
配置好上述配置之后對(duì)prometheus重啟。并在prometheus的alter欄目中查看告警是否觸發(fā)。發(fā)現(xiàn)已經(jīng)觸發(fā)了告警配置。


global:resolve_timeout: 5msmtp_smarthost: 'smtp.qq.com:465'smtp_from: '[email protected]'smtp_auth_username: '[email protected]'smtp_auth_password: '********'smtp_require_tls: falseroute:receiver: mailreceivers:name: 'mail'email_configs:to: '[email protected]'
配置好qq郵箱的報(bào)警提醒之后,我們重啟altermanager。然后看一下是否會(huì)收到報(bào)警的郵件。稍等片刻,在郵箱中收到了郵件,如圖。

早~
評(píng)論
圖片
表情
