mysql> CREATE USER 'mysql_ex'@'%' IDENTIFIED BY '12345678' WITH MAX_USER_CONNECTIONS 3;
Query OK, 0 rows affected (0.02 sec)
mysql> GRANT PROCESS, REPLICATION CLIENT ON *.* TO 'mysql_ex'@'%';
Query OK, 0 rows affected (0.03 sec)
mysql> GRANT SELECT ON performance_schema.* TO 'mysql_ex'@'%';
Query OK, 0 rows affected (0.03 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.04 sec)
---
apiVersion: v1
kind: Service
metadata:
name: mysql-exporter-svc
namespace: monitoring
spec:
ports:
- name: tcp
port: 9104
protocol: TCP
clusterIP: None
selector:
app: mysql-exporter
sessionAffinity: None
type: ClusterIP
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: mysql-exporter
namespace: monitoring
labels:
app: mysql-exporter
spec:
selector:
matchLabels:
app: mysql-exporter
replicas: 1
template:
metadata:
labels:
app: mysql-exporter
spec:
containers:
- name: mysql-exporter
image: "prom/mysqld-exporter:v0.14.0"
imagePullPolicy: IfNotPresent
args:
- --collect.info_schema.tables
- --collect.info_schema.innodb_tablespaces
- --collect.info_schema.innodb_metrics
- --collect.global_status
- --collect.global_variables
- --collect.slave_status
- --collect.info_schema.processlist
- --collect.perf_schema.tablelocks
- --collect.perf_schema.eventsstatements
- --collect.perf_schema.eventsstatementssum
- --collect.perf_schema.eventswaits
- --collect.auto_increment.columns
- --collect.binlog_size
- --collect.perf_schema.tableiowaits
- --collect.perf_schema.indexiowaits
- --collect.info_schema.userstats
- --collect.info_schema.clientstats
- --collect.info_schema.tablestats
- --collect.info_schema.schemastats
- --collect.perf_schema.file_events
- --collect.perf_schema.file_instances
- --collect.perf_schema.replication_group_member_stats
- --collect.perf_schema.replication_applier_status_by_worker
- --collect.slave_hosts
- --collect.info_schema.innodb_cmp
- --collect.info_schema.innodb_cmpmem
- --collect.info_schema.query_response_time
- --collect.engine_tokudb_status
- --collect.engine_innodb_status
resources:
limits:
cpu: 256m
memory: 256Mi
requests:
cpu: 50m
memory: 64Mi
env:
- name: DATA_SOURCE_NAME
value: "mysql_ex:12345678@(192.168.100.64:3306)/"
ports:
- containerPort: 9104
Подключимся на под prometeus и проверим получения метрик
root@prometheus-server-865cc64c6c-b9xrm:/opt/bitnami/prometheus# curl -s mysql-exporter-svc:9104/metrics
mysql_perf_schema_file_instances_total{event_name="wait/io/file/innodb/innodb_data_file",file_name="ibdata1",mode="read"} 10
mysql_perf_schema_file_instances_total{event_name="wait/io/file/innodb/innodb_data_file",file_name="ibdata1",mode="write"} 10
mysql_perf_schema_file_instances_total{event_name="wait/io/file/innodb/innodb_data_file",file_name="ibtmp1",mode="read"} 0
mysql_perf_schema_file_instances_total{event_name="wait/io/file/innodb/innodb_data_file",file_name="ibtmp1",mode="write"} 143
mysql_perf_schema_file_instances_total{event_name="wait/io/file/innodb/innodb_data_file",file_name="mysql.ibd",mode="read"} 305
mysql_perf_schema_file_instances_total{event_name="wait/io/file/innodb/innodb_data_file",file_name="mysql.ibd",mode="write"} 18
mysql_perf_schema_file_instances_total{event_name="wait/io/file/innodb/innodb_data_file",file_name="sys/sys_config.ibd",mode="read"} 1
mysql_perf_schema_file_instances_total{event_name="wait/io/file/innodb/innodb_data_file",file_name="sys/sys_config.ibd",mode="write"} 0
mysql_perf_schema_file_instances_total{event_name="wait/io/file/innodb/innodb_data_file",file_name="undo_001",mode="read"} 272
mysql_perf_schema_file_instances_total{event_name="wait/io/file/innodb/innodb_data_file",file_name="undo_001",mode="write"} 32
mysql_perf_schema_file_instances_total{event_name="wait/io/file/innodb/innodb_data_file",file_name="undo_002",mode="read"} 278
mysql_perf_schema_file_instances_total{event_name="wait/io/file/innodb/innodb_data_file",file_name="undo_002",mode="write"} 21
mysql_perf_schema_file_instances_total{event_name="wait/io/file/innodb/innodb_dblwr_file",file_name="#ib_16384_0.dblwr",mode="read"} 1
mysql_perf_schema_file_instances_total{event_name="wait/io/file/innodb/innodb_dblwr_file",file_name="#ib_16384_0.dblwr",mode="write"} 26
mysql_perf_schema_file_instances_total{event_name="wait/io/file/innodb/innodb_dblwr_file",file_name="#ib_16384_1.dblwr",mode="read"} 1
mysql_perf_schema_file_instances_total{event_name="wait/io/file/innodb/innodb_dblwr_file",file_name="#ib_16384_1.dblwr",mode="write"} 0
mysql_perf_schema_file_instances_total{event_name="wait/io/file/innodb/innodb_log_file",file_name="ib_logfile0",mode="read"} 8
mysql_perf_schema_file_instances_total{event_name="wait/io/file/innodb/innodb_log_file",file_name="ib_logfile0",mode="write"} 65
mysql_perf_schema_file_instances_total{event_name="wait/io/file/innodb/innodb_log_file",file_name="ib_logfile1",mode="read"} 0
mysql_perf_schema_file_instances_total{event_name="wait/io/file/innodb/innodb_log_file",file_name="ib_logfile1",mode="write"} 0
Приведем конфиг prometeus к таком виду и перезапусим под
global:
scrape_interval: 15s
evaluation_interval: 15s
alerting:
alertmanagers:
- static_configs:
- targets:
# - alertmanager:9093
rule_files:
# - "first_rules.yml"
# - "second_rules.yml"
scrape_configs:
- job_name: "prometheus"
static_configs:
- targets: ["localhost:9090"]
- job_name: "haproxy"
static_configs:
- targets: ["haproxy-exporter-svc:9101"]
labels:
alias: "haproxy"
- job_name: "mysql"
static_configs:
- targets: ["mysql-exporter-svc:9104"]
labels:
alias: "mysql"
Проверим отображения метрик
PS Дальше делаем отображение в grafana, шаблон можно найти в интернете