mysqld_exporter mysql指标
最后更新于:2022-04-02 03:00:15
[TOC]
> [github mysqld_exporter](https://github.com/prometheus/mysqld_exporter)
## 收集 MySQL 指标
支持版本:
* MySQL >= 5.6.
* MariaDB >= 10.1
>[warning] 注意:MySQL / MariaDB <5.6上不支持所有收集方法
>
## 安装
在github release 下载最新版
```
wget https://github.com/prometheus/mysqld_exporter/releases/download/v0.11.0/mysqld_exporter-0.11.0.linux-amd64.tar.gz \
&& tar xvfz mysqld_exporter-0.11.0.linux-amd64.tar.gz \
&& cd mysqld_exporter-0.11.0.linux-amd64/
```
## 使用
方式一:
```
$ export DATA_SOURCE_NAME='root:123456@(192.168.0.107:3306)/'
$ ./mysqld_exporter
```
方式二:
```
> cat .my.cnf
[client]
host=localhost
port=3306
user=root
password=123456
> ./mysqld_exporter --config.my-cnf=".my.cnf"
```
## 修改 prometheus.yaml
```
scrape_configs:
- job_name: 'mysql'
static_configs:
- targets: ['192.168.0.107:9104']
```
### 重启服务
docker
```
docker restart prometheus_id
```
原生安装,直接发送`HUP`型号
```
killall -HUP prometheus
```
### 验证服务是否开启
查看 prometheus web `http://192.168.0.229:9090/targets`查看是否添加
### 添加到 grafana
1. 查看常用 [mysql dashboards](https://github.com/percona/grafana-dashboards)
1. 查看 https://grafana.com/grafana/dashboards 搜索 "MySQL Overview",并复制id
2. 进入 grafana, dashboard->manage->import-> 输入id
';