kube-prometheus-stack版本45.8.0,安装mysql和用户授权略,需要请查看之前的文章
1、安装mysql-exporter
[root@master]# helm search repo prometheus-community
[root@master]# helm fetch prometheus-community/prometheus-mysql-exporter
[root@master]# tar xf prometheus-mysql-exporter-1.13.0.tgz
#通过wget下载
[root@master]# wget https://github.com/prometheus-community/helm-charts/releases/download/prometheus-mysql-exporter-1.13.0/prometheus-mysqlexporter-1.13.0.tgz
[root@master]# tar xf prometheus-mysql-exporter-1.13.0.tgz
[root@master]# grep -A 2 'image:' prometheus-mysql-exporter/*
[root@master]# grep -rn 'quay.io' prometheus-mysql-exporter/*
#批量替换
[root@master]# sed -i 's/quay.io/quay.mirrors.ustc.edu.cn/g' `grep "quay.io" -rl
prometheus-mysql-exporter/*`
2、安装prometheus-mysql-exporter
[root@master]# helm install -n monitoring --create-namespace prometheus-mysql-exporter
prometheus-mysql-exporter
#如果修改了配置文件
[root@master]# helm -n monitoring upgrade prometheus-mysql-exporter prometheus-mysql exporter
3、检查pod是否正常启动
[root@master]# kubectl get pod -n monitoring
4、创建告警规则
[root@master]# cat >> prometheus-mysql-exporter-rules.yml 0
for: 2m
labels:
severity: warning
annotations:
summary: "Mysql慢日志告警,实例: {{ $labels.instance }}"
description: "MySQL在过去2分钟有新的{{ $value }}条慢查询"
#MySQL innodb日志写入停滞
- alert: MysqlInnodbLogWaits
expr: rate(mysql_global_status_innodb_log_waits[15m]) > 10
for: 0m
labels:
severity: warning
annotations:
summary: "MySQL innodb日志等待,实例: {{ $labels.instance }}"
description: "MySQL innodb日志写入停滞,当前值:{{ $value }}"
- alert: MysqlRestarted
expr: mysql_global_status_uptime < 60
for: 0m
labels:
severity: info
annotations:
summary: "MySQL 重启,实例: {{ $labels.instance }}"
description: "不到一分钟前,MySQL重启过"
EOF
[root@master]# kubectl create -f prometheus-mysql-exporter-rules.yml
5、测试
把mysql停止看下是否告警出来
[root@master]# kubectl scale --replicas=0 deployment mysql #把mysql的副本设置为0
#检查
[root@master]# kubectl get pod -o wide
----------------------end---------------------
推荐阅读
1.K8s最佳实践Kubernetes-Rancher2.x持续交付与自动化运维
2.MySQL8.0 DBA存储架构+存储引擎+SQL优化+InnoDB的存储架构
3.企业级Elasticsearch 8.X技术来临!性能优化与集群部署 基础与进阶全面实战
4.Nginx通过Lua+Redis实现WAF动态封禁IP
5.运维必备的MySQL+Python运维实战课程
6.运维不会Python Web就落伍了!
7.企业级微服务API网关架构实战Nginx+Lua+Openresty
8.高级运维工程师的打怪升级之路 Docker+Jenkins+Kubernetes
9.下载链接-Docker+K8S的高可用集群+自建集群实战
10.Kubernetes持久化实战 K8S集群部署+Jenkins自动化构建
11.企业级Redis入门到精通 Redis基础+进阶+实战应用+项目实战
如果本文对你有帮助的话,欢迎点赞&在看&转发,这对我继续分享&创作优质文章非常重要。感谢🙏🏻
请点赞→点亮“在看”→分享
↓↓↓