使用docker部署prometheus和grafana 并监控mysql 配置告警
上图是发送告警的截图
grafana 监控mysql的图片
需要部署5个容器
docker run -d -p 9104:9104 --network mysql-network --name mysql-exporter -e DATA_SOURCE_NAME="root:123456@(192.168.244.13:3306)/" prom/mysqld-exporter docker run -d -p 9090:9090 --name prometheus -v E:\docker-configs\prometheus.yml:/etc/prometheus/prometheus.yml -v E:\docker-configs\rules\1.rules:/usr/local/prometheus/rules/1.rules prom/prometheus docker run -d -p 3000:3000 --name=grafana -v E:\docker-configs\grafana-storage\:/var/lib/grafana grafana/grafana docker run --name alertmanager -d -p 9093:9093 prom/alertmanager:latest
prometheus.yml
global: scrape_interval: 60s evaluation_interval: 60s alerting: alertmanagers: - static_configs: - targets: [192.168.244.13:9093] rule_files: - "/usr/local/prometheus/rules/*.rules" scrape_configs: - job_name: prometheus static_configs: - targets: ['localhost:9090'] labels: instance: prometheus - job_name: mysql static_configs: - targets: ['192.168.244.13:9104'] labels: instance: mysql-master
1.rules
groups: - name: node-up rules: - alert: node-up expr: mysql_global_status_mysqlx_sessions{job="mysql"} == 0 for: 15s labels: severity: 1 team: node annotations: summary: "{{ $labels.instance }} 已停止运行!" description: "{{ $labels.instance }} 检测到异常停止!请重点关注!!!"