Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to parse MySQL prometheus email alarm configuration

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)05/31 Report--

This article introduces prometheus how to configure MySQL email alarm, the content is very detailed, interested friends can refer to, hope to be helpful to you.

Here is an introduction to the email alarm configuration of prometheus.

Alertmanager download

The alertmanager component is required for prometheus alarm configuration, which can be downloaded from the prometheus official website.

Https://prometheus.io/download/

Due to some problems with the latest version of alertmanager component configuration mailbox communication, we chose to download version 0.14 of alertmanager on github.

Https://github.com/prometheus/alertmanager

The specific download address is attached:

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

Alertmanager installation configuration

Unpack and install the downloaded alertmanager package.

Tar-xf alertmanager-0.14.0.linux-amd64.tar.gzmv alertmanager-0.14.0.linux-amd64 / data/alertmanager

Edit the configuration file of alertmanager and add mailbox information.

# cd / data/alertmanager# cat alertmanager.ymlglobal: smtp_smarthost: smtp.exmail.xxx.com:465 # Sender smtp address smtp_auth_username: xxxx@xxx.com # Sender email account smtp_from: xxx@xxx.com # Sender email account smtp_auth_password: xxxxxx # Sender email password resolve_timeout: 5m smtp_require_tls: falseroute: # group_by: ['alertname'] # alarm grouping based on group_wait: 10s # Notification of how long to send a group of alerts initially, that is, how long to wait for the first time group_interval: 10s # waiting time before sending new alerts repeat_interval: 1m # how frequent is the period of sending repeated alerts for email configuration receiver: 'email'receivers:- name: email email_configs:-send_resolved: true to: xxx@xxx.com # recipient mailbox account

Start alertmanager.

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

The default port for alertmanager is 9093.

Prometheus configuration

Edit the alarm template alert_rules.yml in the prometheus directory and add some custom alarm items. # cd / data/prometheus# cat alert_rules.ymlgroups:- name: MySQL-rules rules:-alert: MySQL Status # alarm name expr: up = = 0 for: 5s # how long after the alarm condition is met before the alarm annotations: # parsing entry is sent. Explain the alarm message summary: "{{$labels.instance}: MySQL has stop!" Value: "{{$value}}" alertname: "MySQL database stops running" description: "detect MySQL database running status" message: the current database instance {{$labels.instance}} has stopped running, please deal with-alert: MySQL Slave IO Thread Status # alarm name expr: mysql_slave_status_slave_io_running = = 0 for: 5s # how long after the alarm condition is satisfied The alarm annotations: # parsing item will be sent to explain the alarm message summary: "{{$labels.instance}}: MySQL Slave IO Thread has stop!!" Value: "{{$value}}" alertname: "MySQL master-slave IO thread stops running" description: "detect the running status of MySQL master-slave IO thread" message: current database instance {{$labels.instance}} IO thread has stopped running Please deal with-alert: MySQL Slave SQL Thread Status # alarm name expr: mysql_slave_status_slave_sql_running = = 0 for: 5s # how long after the alarm condition is met before the alarm annotations: # parsing entry will be sent. Explain the alarm message summary: "{{$labels.instance}}: MySQL Slave SQL Thread has stop!!" Value: "{{$value}}" alertname: "MySQL master-slave SQL thread stops running" description: "detect the running status of MySQL master-slave SQL thread" message: the current database instance {{$SQL}} SQL thread has stopped running, please deal with-alert: MySQL Slave Delay Status # alarm name expr: mysql_slave_status_sql_delay = = 30 SQL: 5s # how long after the alarm condition is satisfied The alarm annotations: # parsing item will be sent to explain the alarm message summary: "{{$labels.instance}}: MySQL Slave Delay has more than 30s!!" Value: "{{$value}}" alertname: "MySQL master-slave delay is too large" description: "detect MySQL master-slave delay status" message: the current database instance {{$labels.instance}} master-slave delay status has exceeded 30s, please deal with it in time

Edit the configuration file for prometheus in the prometheus directory to add the monitored configuration information to prometheus.yml.

# cd / data/prometheus# cat prometheus.yml# 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:-static_configs:-targets:-172.18.0.24 targets 9093 # corresponding to port 9093 of the launched altermanager node # Load rules once and periodically evaluate them according to the global 'evaluation_interval'.rule_files:-"alert_rules.yml" # corresponds to the previously edited alarm template alert_rules.yml file # 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

When the editing is complete, reload the configuration changes.

Kill-HUP [prometheus PID]

Verify email alarm

Log on to the web page of prometheus to view the alarm message.

Enter Prometheus_IP:9090 in the browser to see the status of each alarm item.

Stop the master-slave thread and simulate and trigger the alarm.

When the Slave SQL thread stops, the alarm color turns yellow, and after the duration exceeds the defined duration, the color turns red, and an email is sent.

I got a 911 email.

About prometheus how to configure MySQL mail alarm to share here, I hope the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report