Promethesu单个mysqld_export监控多个mysql

在日常运维中经常会遇到有多个mysql要监控,如果每个mysql启动一个export显然太浪费资源了,那么其实prometheus是有通过传参给export的然后进行监控的方式,下面我们来具体介绍一下。(测试的话msyql自己安装就好)

1、安装mysqld_exporter

解压

tar xf mysqld_exporter-0.12.1.linux-amd64.tar.gz -C /opt/

2、创建系统服务启动配置文件mysqld_exporter.service

root@localhost ~]# vi /usr/lib/systemd/system/mysqld_exporter.service
[Unit]
Description=Prometheus MySQL daemon
After=network.target




[Service]
User=root
Group=root
Type=simple
Restart=always
ExecStart=/opt/mysqld_exporter/mysqld_exporter \--collect.global_status \
    --collect.auto_increment.columns \
    --collect.info_schema.processlist \
    --collect.binlog_size \
    --collect.info_schema.tablestats \
    --collect.global_variables \
    --collect.info_schema.innodb_metrics \
    --collect.info_schema.query_response_time \
    --collect.info_schema.userstats \
    --collect.info_schema.tables \
    --collect.perf_schema.tablelocks \
    --collect.perf_schema.file_events \
    --collect.perf_schema.eventswaits \
    --collect.perf_schema.indexiowaits \
    --collect.perf_schema.tableiowaits \
    --collect.slave_status \
    --web.listen-address=0.0.0.0:9104




[Install]
WantedBy=multi-user.target




[root@localhost ~]# systemctl daemon-reload
[root@localhost ~]# systemctl start mysqld_exporter

 

3、与prometheus集成

- job_name: mysql_exporter
  honor_timestamps: true
  scrape_interval: 15s
  scrape_timeout: 15s
  metrics_path: /probe
  scheme: http
  relabel_configs:
  - source_labels: [__address__]
    separator: ;
    regex: (.*)
    target_label: __param_dsn
    replacement: $1
    action: replace
  - source_labels: [__param_dsn]
    separator: ;
    regex: .*tcp\((.*?)\).*
    target_label: instance
    replacement: $1
    action: replace
  - separator: ;
    regex: (.*)
    target_label: __address__
    replacement: localhost:9105
    action: replace
  file_sd_configs:
  - files:
    - /prometheus/mysql.yml
  

4、编写mysql.yml

- targets: [mysqld_exporter:123456@tcp(172.16.149.216:3306)/]
  labels:
    instance_id: 216mysql
    role: master
    alias: "test"
    host: "172.16.149.216"
    prot: "3306"
    usr: mysqld_exporter
    instance: '172.16.149.216:3306'


- targets: [mysqld_exporter:123456@tcp(172.16.149.217:3306)/]
  labels:
    instance_id: 217mysql
    role: master
    alias: "test"
    host: "172.16.149.217"
    prot: "3306"
    usr: mysqld_exporter
    instance: '172.16.149.217:3306'

5、页面查看mysql是否正常

 

 

至此我们已经部署完毕至于配置grafana 这里就不过多介绍了。官网有模板也可以自己弄

posted @ 2022-05-19 15:56  Throb_JL  阅读(968)  评论(0编辑  收藏  举报