赞
踩
mysqld_exporter是一个用于收集MySQL数据库指标的开源软件,它是Prometheus生态系统中的一个组件。mysqld_exporter运行在MySQL服务器上,并通过执行SHOW STATUS和SHOW VARIABLES等MySQL内置命令来获取各种与数据库性能、连接状态、查询执行等相关的指标信息。
mysqld_exporter可以提供大量关于MySQL数据库的指标,例如查询执行情况(如查询次数、响应时间)、连接数、缓存命中率、InnoDB引擎相关的统计信息等。这些指标可以帮助管理员了解MySQL数据库的健康状况和性能瓶颈,并进行监控和优化。
通过将mysqld_exporter与Prometheus结合使用,系统管理员可以定期从mysqld_exporter暴露的HTTP或HTTPS端点获取MySQL数据库的指标数据,并将其存储、分析和可视化。使用Prometheus的查询语言,用户可以构建自定义的监控规则和警报条件,以便在出现问题时及时发出警报并采取适当的措施。
vim /mysqld_exporter.sh
- #!/bin/bash
- # -*- coding: utf-8 -*-
- # Author: make.han
- # Email: CIASM@CIASM
- # Date: 2024/01/12
-
- OPT_CATALOGUE=/opt
- MYSQLD_EXPORTER_PREFIX=/opt/mysqld_exporter
- MYSQLD_EXPORTER_URL=https://github.com/prometheus/mysqld_exporter/releases/download/v0.15.1/mysqld_exporter-0.15.1.linux-amd64.tar.gz
- MYSQLD_EXPORTER_GZ=mysqld_exporter-0.15.1.linux-amd64.tar.gz
- MYSQLD_EXPORTER_DIRECTORY=mysqld_exporter-0.15.1.linux-amd64
- MYSQLD_EXPORTER_NEW=mysqld_exporter
- MYSQLD_EXPORTER_PORT=9104
-
- install_mysqld_exporter (){
- if [ ! -d ${MYSQLD_EXPORTER_PREFIX} ];then
-
- # selinux stop
- setenforce 0
- sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config
-
- if [ $? -eq 0 ];then
-
- echo "download mysqld_exporter"
- curl -o $OPT_CATALOGUE/$MYSQLD_EXPORTER_GZ $MYSQLD_EXPORTER_URL
-
- echo "download mysqld_exporter"
- tar -xf $OPT_CATALOGUE/$MYSQLD_EXPORTER_GZ -C $OPT_CATALOGUE
- mv $OPT_CATALOGUE/$MYSQLD_EXPORTER_DIRECTORY $MYSQLD_EXPORTER_PREFIX
-
- echo "config mysqld_exporter"
- cat >>$MYSQLD_EXPORTER_PREFIX/.my.cnf<<EOF
- [client]
- host=192.168.11.98
- port=3306
- user=root
- password=root
- EOF
-
- echo "firewall mysqld_exporter port"
- firewall-cmd --zone=public --add-port=$MYSQLD_EXPORTER_PORT/tcp --permanent && firewall-cmd --reload
-
- echo "add mysqld_exporter.service"
- cat >>/usr/lib/systemd/system/mysqld_exporter.service<<EOF
- [Unit]
- Description=mysqld_exporter
- Documentation=https://prometheus.io/
- Wants=network-online.target
- After=network-online.target
-
- [Service]
- User=root
- Group=root
- Type=simple
- ExecStart=$MYSQLD_EXPORTER_PREFIX/mysqld_exporter --config.my-cnf=$MYSQLD_EXPORTER_PREFIX/.my.cnf
-
- Restart=on-failure
-
- [Install]
- WantedBy=multi-user.target
- EOF
-
- echo "start mysqld_exporter.service"
- systemctl daemon-reload
- systemctl enable --now mysqld_exporter
-
- echo -e "\033[32mThe mysqld exporter Install Sussess...\033[0m"
- else
- echo -e "\033[33mThe mysqld_exporter Install Failed...\033[0m"
- exit 1
- fi
- else
- echo -e "\033[31mThe mysqld_exporter Install already...\033[0m"
- fi
- }
-
- main (){
- install_mysqld_exporter
- }
-
- main
sh /mysqld_exporter.sh
- scrape_configs:
- - job_name: 'web'
- scrape_interval: 5s
- static_configs:
- - targets:
- - localhost:9090
-
- - job_name: 'mysql-Host-monitoring'
- scrape_interval: 5s
- static_configs:
- - targets:
- - 192.168.11.98:9104
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。