This article has participated in the “Digitalstar Project” and won a creative gift package to challenge the creative incentive money.
1 background
MySQL is designed and developed by the community specifically for collecting MySQL/MariaDB database monitoring indicators. Through my Exporter, I can export the core database indicators to alarm exceptions and monitor the market display. Cloud monitoring Prometheus provides a Grafana monitor with MySQL Half integration and out of the box.
Currently, My friend supports MySQL up to version 5.6 and MariaDB up to version 10.1. If the MySQL/MariaDB version is earlier than 5.6, some monitoring indicators may not be collected.
This article will demonstrate how to report data collection from the cloud database MySQL to cloud native monitoring and visualize data using Grafana by configuring MySQL Exporter. You have a good view of database performance and know where to check if you encounter problems.
This document will have three main steps:
- Database Authorization
helm Chart
The deployment ofMySQL Prometheus exporter
- create
MySQL Grafana
The dashboard
The experimental environment is prepared as follows:
- Kubernetes Cluster (Tencent TKE)
- Prometheus Monitoring (Tencent Cloud native Monitoring)
- MySQL (Tencent CDB)
2 Database Authorization
Because MySQL is monitored by querying the status data in the database, it requires authorization for the corresponding database instance. The account and password vary according to actual conditions. The authorization procedure is as follows:
-
Log in to the MySQL console of the cloud database.
-
On the instance list page, click the name of the database to be authorized. The database details page is displayed.
-
Choose Database Management > Account Management to access the account management page, and create an account based on service requirements.
-
Click Modify Rights on the right of the account to modify the corresponding rights. An example is shown below:
At this point, database authorization is complete.
3 Deploy Exporter on the Helm Charts
Helm pull Prometheus -community/ Prometheus -mysql-exporter tar ZXF Prometheus -mysql-exporter-1.2.0.tgz helm pull Prometheus -community/ Prometheus -mysql-exporter tar ZXF Prometheus -mysql-exporter-1.2.0.tgz [Promethes-mysql-exporters] Tree. ├── Chart. ├─ Md ├── ─ NOTES Deployment. Yaml │ ├ ─ ─ secret - env. Yaml │ ├ ─ ─ secret. The yaml │ ├ ─ ─ service. The yaml │ └ ─ ─ servicemonitor. Yaml └ ─ ─ values. The yaml 1 directory, 10 filesCopy the code
You need to modify the project values.yaml here
[prometheus-mysql-exporter] helm install mysql-exporter . NAME: mysql-exporter LAST DEPLOYED: Wed Oct 27 15:36:31 2021 NAMESPACE: default STATUS: deployed REVISION: 1 TEST SUITE: None NOTES: 1. Get the application URL by running these commands: export POD_NAME=$(kubectl get pods --namespace default -l "app.kubernetes.io/name=prometheus-mysql-exporter,app.kubernetes.io/instance=mysql-exporter" -o Jsonpath ="{.items[0].metadata.name}") echo "Visit http://127.0.0.1:9104 to use your application" kubectl --namespace default port-forward $POD_NAME 9104 [prometheus-mysql-exporter] helm ls NAME NAMESPACE REVISION UPDATED STATUS CHART APP VERSION mysql-mine default 1 2021-10-27 15:36:31.079294 +0800 CST Deployed Prometheus - MYSqL-mine - 1.2.0v0.12.1Copy the code
[~] kubectl logs mysql-exporter-prometheus-mysql-exporter-79ff48ffcc-5hzr5 time="2021-10-27T07:36:36Z" level=info MSG = "Starting mysqld_exporter (version = 0.12.1, branch = HEAD, revision=48667bf7c3b438b5e93b259f3d17b70a7c9aff96)" source="mysqld_exporter.go:257" time="2021-10-27T07:36:36Z" MSG ="Build context (go=go1.12.7, user=root@0b3e56a7bc0a, date=20190729-12:35:58)" source="mysqld_exporter.go:258" time="2021-10-27T07:36:36Z" level=info msg="Enabled scrapers:" source="mysqld_exporter.go:269" time="2021-10-27T07:36:36Z" level=info msg=" --collect.global_variables" source="mysqld_exporter.go:273" time="2021-10-27T07:36:36Z" level=info msg=" --collect.slave_status" source="mysqld_exporter.go:273" time="2021-10-27T07:36:36Z" level=info msg=" --collect.global_status" source="mysqld_exporter.go:273" time="2021-10-27T07:36:36Z" level=info msg=" --collect.info_schema.query_response_time" source="mysqld_exporter.go:273" time="2021-10-27T07:36:36Z" level=info msg=" --collect.info_schema.innodb_cmp" source="mysqld_exporter.go:273" time="2021-10-27T07:36:36Z" level=info msg=" --collect.info_schema.innodb_cmpmem" source="mysqld_exporter.go:273" time="2021-10-27T07:36:36Z" level=info msg="Listening on :9104" source="mysqld_exporter.go:283"Copy the code
Check the indicator
[root @ VM - 1-27 - centos ~] # curl 172.17.253.96:9104 / metrics | grep Received Total mysql_up % % % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 142k 0 142k 0 0 6174k 0 --:--:-- --:--:-- --:--:-- 6499k # HELP mysql_up Whether the MySQL server is up. # TYPE mysql_up gauge mysql_up 1Copy the code