您的位置 首页 prometheus

altermanager 对mysql  告警(mysql告警规则文件)

altermanager 对mysql  告警

配置 prometheus

vim prometheus.yml
# Alertmanager configuration
alerting:
  alertmanagers:
    - static_configs:
        - targets: ['10.0.0.205:9093']
       

# Load rules once and periodically evaluate them according to the global 'evaluation_interval'.
rule_files:
  # - "first_rules.yml"
   - "/app/prometheus/rules/*_rules.yml"

 

 

cd /app/prometheus/rules

vim mysql_rules.yml

准备mysql告警规则文件 , 注意该文件不能有tag键, 同时key和value之间必须要有空格。

 

 

groups:
- name: MySQLStatsAlert
  rules:
  - alert: MySQL is down
    expr: mysql_up == 0
    for: 1m
    labels:
        severity: critical
    annotations:
        summary: "Instance {{ $labels.instance }} MySQL is down"
        description: "MySQL database is down. This requires immediate action!"

  - alert: Mysql_High_QPS
    expr: rate(mysql_global_status_questions[5m]) > 500 
    for: 2m
    labels:
        severity: warning
    annotations:
        summary: "{{$labels.instance}}: Mysql_High_QPS detected"
        description: "{{$labels.instance}}: Mysql opreation is more than 500 per second ,(current value is: {{ $value }})"  
  - alert: Mysql_Too_Many_Connections
    expr: rate(mysql_global_status_threads_connected[5m]) > 200
    for: 2m
    labels:
        severity: warning
    annotations:
        summary: "{{$labels.instance}}: Mysql Too Many Connections detected"
        description: "{{$labels.instance}}: Mysql Connections is more than 100 per second ,(current value is: {{ $value }})"  

  - alert: Mysql_Too_Many_slow_queries
    expr: rate(mysql_global_status_slow_queries[5m]) > 3
    for: 2m
    labels:
        severity: warning
    annotations:
        summary: "{{$labels.instance}}: Mysql_Too_Many_slow_queries detected"
        description: "{{$labels.instance}}: Mysql slow_queries is more than 3 per second ,(current value is: {{ $value }})"  

  - alert: SQL thread stopped
    expr: mysql_slave_status_slave_sql_running != 1
    for: 1m
    labels:
        severity: critical
    annotations:
        summary: "Instance {{ $labels.instance }} Sync Binlog is enabled"
        description: "SQL thread has stopped. This is usually because it cannot apply a SQL statement received from the master."
  - alert: Slave lagging behind Master
    expr: rate(mysql_slave_status_seconds_behind_master[5m]) >30 
    for: 1m
    labels:
        severity: warning 
    annotations:
        summary: "Instance {{ $labels.instance }} Slave lagging behind Master"
        description: "Slave is lagging behind Master. Please check if Slave threads are running and if there are some performance issues!"

 

 

关闭mysql ,大概等1分钟 就报警。

 

 

这个时候,我们去altermanager 界面,去看看

http://10.0.0.205:9093/#/alerts

欢迎来撩 : 汇总all

白眉大叔

关于白眉大叔linux云计算: 白眉大叔

热门文章