prometheus监控mysql指标_Prometheus监控MySQL服务
(六)
⼀、监控使⽤mysqld_exporter插件
⽀持的MySQL和MariaDB版本:5.5及以上,需要注意的MySQL/MariaDB<5.6并不⽀持所有的收集⽅法
# tar xf mysqld_exporter-0.12.1. -C /usr/local/#ln -s /usr/local/mysqld_exporter-0.12.1.linux-amd64/
/usr/local/mysqld_exporter
# cd/usr/local/mysqld_exporter
# 查看需要监控的指标
# ./mysqld_exporter --help
⼆、在MySQL中创建帐号
# mysql -uroot -p
mysql> CREATE USER 'exporter'@'192.168.5.237' IDENTIFIED BY 'exporter';
GRANT PROCESS, REPLICATION CLIENT, SELECT ON*.* TO 'exporter'@'192.168.5.237';Query OK, 0 rows affected
(0.03sec)
mysql> GRANT PROCESS, REPLICATION CLIENT, SELECT ON *.* TO 'exporter'@'192.168.5.237';
Query OK,0 rows affected (0.00 sec)
三、创建客户端连接mysql的默认帐号
# vim /usr/local/mysqld_exporter/.myf
[client]
host=192.168.5.237
user=exporter
password=exporter
四、启动mysqld_exporter服务
# /usr/local/mysqld_exporter/mysqld_exporter ---cnf='/usr/local/mysqld_exporter/.myf' &INFO[0000] Starting mysqld_exporter (version=0.12.1, branch=HEAD, revision=48667bf7c3b438b5e93b259f3d17b70a7c9aff96) source=":257"INFO[0000] Build context (go=go1.12.7, user=root@0b3e56a7bc0a, date=20190729-12:35:58) source=":258"INFO[0000] Enabled scrapers: source=":269"INFO[0000] --collect.global_status source=":273"INFO[0000] --collect.global_variables
source=":273"INFO[0000] --collect.slave_status source=":273"INFO[0000] --collect.info_schema.innodb_cmp source=":273"INFO[0000] --collect.info_schema.innodb_cmpmem source=":273"INFO[0000] --collect.info_schema.query_response_time
source=":273"INFO[0000] Listening on :9104 source=":283"
可以通过9104端⼝查看暴露的监控数据
五、修改Pormetheus配置⽂件
# vim /usr/local/l
# my global config
global:
scrape_interval: 15s # Set the scrape interval to every15 seconds. Default is every 1minute.
evaluation_interval: 15s # Evaluate rules every15 seconds. The default is every 1minute.
alerting:
alertmanagers:-static_configs:-targets:
#- alertmanager:9093rule_files:
#- "l"#- "l"scrape_configs:- job_name: 'prometheus'# metrics_path defaults to'/metrics'# scheme defaults to'http'.
static_configs:- targets: ['192.168.5.237:9090']- job_name: 'node'file_sd_configs:-refresh_interval: 30s
files:- "/usr/local/prometheus/sd_config/node*.yml"
- job_name: 'docker'static_configs:- targets: ['192.168.5.85:8080']
# 增加如下信息- job_name: 'mysql'static_configs:- targets: ['192.168.5.237:9104']
labels:
app: zabbix-server-mysql
# 检查配置⽂件
#/usr/local/prometheus/promtool check config /usr/local/l
Checking/usr/local/l
SUCCESS:0rule files found
# 重启服务
# systemctl restart prometheus.service
Targets中能查看到mysql的信息
六、配置Grafana图表
导⼊7362图表,并选择prometheus数据源
能查看到监控数据
七、将mysqld_exporter配置为服务
# vim /usr/lib/systemd/system/mysqld_exporter.service
[Unit]
Description=node_exporter
After=network.target
[Service]
Type=simple
User=rootExecStart=/usr/local/mysqld_exporter/mysqld_exporter ---cnf=/usr/local/mysqld_exporter/.myf
Restart=on-failure
[Install]
WantedBy=multi-user.target
# systemctl daemon-reload
# systemctl start mysqld_exporter.service
# systemctl enable mysqld_exporter.service
⼋、多数据库配置使⽤
参照github上提供的⽅法,使⽤docker启动多个容器对不同的实例进⾏采集
docker run -d \-p 9104:9104\--network my-mysql-network \-e
DATA_SOURCE_NAME="user:password@(hostname:3306)/"\
prom/mysqld-exporter
可以写成docker-compose的⽅法
# l
version:'3.7'services:
mysql-master:
restart: always
image: prom/mysqld-exporter
privileged:trueenvironment:- 'DATA_SOURCE_NAME=root:password@(10.1.1.6:3306)/'ports:- 9103:9104mysql-slave:
restart: always
image: prom/mysqld-exporter
privileged:trueenvironment:- 'DATA_SOURCE_NAME=root:password@(10.1.1.7:3306)/'ports:- 9104:9104# docker-compose up -d
启动之后,然后再配置prometheus
- job_name: 'mysql'metrics_path:/metrics
static_configs:- targets: ['10.1.1.6:9103']mysql下载app
labels:
instance: MySQL-master- targets: ['10.1.1.7:9104']
labels:
instance: MySQL-slave
重新加载prometheus配置⽂件

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。