当前位置:网站首页>Use prometheus+grafana to monitor MySQL performance indicators
Use prometheus+grafana to monitor MySQL performance indicators
2022-07-24 17:42:00 【wespten】
One 、 Download and install
To configure Prometheus+Grafana, Take a quick look at MySQL Connection number , lock , Memory , Network and other indicators .
Prometheus Official website download address :Download | Prometheus
This download address is generally only the latest version , If you want to download another version , Need to github On Mysqld_exporter Of github Download address :Releases · prometheus/mysqld_exporter · GitHub
Download here 11 edition ( Must be 11 edition , Or the back grafana Unable to display graphics )
Mysqld_exporter 11 Version download address :https://github.com/prometheus/mysqld_exporter/releases/download/v0.11.0/mysqld_exporter-0.11.0.linux-amd64.tar.gz
Baidu online address :
link : Baidu SkyDrive Please enter the extraction code
Extraction code :brkn
Two 、MySQL To configure
I am here centOS System , In case of other systems, relevant information of the system is required :

# Navigate to the installation directory
cd /usr/local
# Upload the files downloaded locally to Linux The server
rz
# Unzip the file
tar -xzvf mysqld_exporter-0.11.1.linux-amd64.tar.gz
# Change the file directory name to mysqld_exporter
mv mysqld_exporter-0.11.1.linux-amd64 mysqld_exporter
mysqld_exporter Connection required Mysql, First, create users for it and give them the required permissions :
# establish exporter user grant all privileges on *.* to 'user'@'%' identified by '123456'
GRANT ALL ON *.* TO 'exporter'@'localhost' identified by '123456';
# Create database
CREATE DATABASE test_db;
# Give query permission
GRANT SELECT ON test_db.* TO 'exporter'@'localhost';
# Refresh the permissions
flush privileges;establish .my.cnf file :
[client]
user=exporter
password=123456
start-up mysqld_exporter
Start mode 1 :
# start-up mysqld_exporter
./mysqld_exporter --config.my-cnf=/etc/my.cnf
# Check the port opening and emptying
ss -tln | grep 9104
Start common parameters :
# Select acquisition innodb
--collect.info_schema.innodb_cmp
# innodb Storage engine status
--collect.engine_innodb_status
# Specify profile
--config.my-cnf="/etc/my.cnf"Add system services :
vi /usr/lib/systemd/system/mysql_exporter.service
[Unit]
Description=https://prometheus.io
[Service]
Restart=on-failure
ExecStart=/usr/local/mysql_exporter/mysqld_exporter --config.my-cnf=/etc/my.cnf
[Install]
WantedBy=multi-user.targetStart the added system service :
systemctl daemon-reload
systemctl restart mysql_exporter.serviceThe startup log can be in /var/log/messages View in .
see MySQLd exporter Capture mysql data
Open the server with a browser IP: 9104, And then click Metrics, The following figure shows the success of data acquisition .


3、 ... and 、Prometheus To configure
1. Prometheus
Previously introduced Prometheus It is an open source monitoring system , Compared with other monitoring systems , It's easy to manage , Monitor the internal running state of the service , Powerful data model , Powerful query language PromQL, Efficient , Scalable , Easy to integrate , visualization , Openness and many other functions .
Official website details :Exporter What is it? - prometheus-book
2. Exporter
All can be directed to Prometheus Programs that provide monitoring sample data can be called a Exporter. and Exporter An example of is called target, As shown below ,Prometheus Periodically from these... By polling target Get sample data from :

Exporter There are also two sources of , They are provided by the community , Include database (MySQL Exporter, Redis Exporter etc. ), Message queue ( Kafka Exporter, RabbitMQ Exporter etc. ), Storage ,HTTP service , journal , Monitoring services, etc . In addition, user-defined Exporter, Users can be based on Prometheus Provided Client Library Create your own Exporter Program .
3. MySQLD Exporter
Prometheus Provided MySQLD Exporter Realize to MySQL Monitoring and measurement of database performance and resource utilization .
Here we use docker compose How to deploy Exporter,docker-compose.yml:
version: '3'
services:
mysqlexporter:
image: prom/mysqld-exporter
ports:
- "9104:9104"
environment:
- DATA_SOURCE_NAME=root:[email protected](mysql:3306)/databaseRun the command docker-compose up -d start-up Exporter.
4. To configure prometheus.yml
Need to be in prometheus.yml Add the following configuration to the file before it can be added to the monitoring .
scrape_configs:
# Add a job and name
- job_name: 'mysql'
# Static add node
static_configs:
# Specify monitoring end
- targets: [' database server IP:9104']Then run the following named restart Prometheus:
docker-compose down
docker-compose up -dInstallation directory startup mode :
# Locate the prometheus The installation directory
cd /usr/local/prometheus/prometheus-2.23.0.linux-amd64
# Execute startup
./prometheus --config.file=prometheus.yml &then , Can be entered in the browser http://127.0.01:9090/targets, We see that it has been added successfully .
Here's the picture ,9104 It is monitored mysql_reporter:

Use promSQL see Mysql Monitoring information :
mysql_global_status_aborted_clients
Click on Graph You can see the monitored MySQL Indicators of :

The next step is to Grafana Add data sources to , Import dashboard template .
Four 、Grafana To configure
1. start-up grafana
service grafana-server start![]()
perform ps -ef | grep grafana, Check to see if startup succeeded .

Browser input http:// install Grafana The server IP:3000/, Then log in grafana.

2. create data source
First , Open it in a browser grafana The address of , Click add data source .

choice Prometheus.

Enter the data source name , Data source address , Click Add .

3. Create dashboard
Click... On the left menu bar 【 establish 】, Click on 【 Import 】, Of course, you can also choose to create a dashboard here , Choose your own components and customize the layout to complete .

Enter the name of the dashboard , Select data source , Click Import to successfully create the dashboard .

The final dashboard is as follows :


5、 ... and 、 Problems encountered
problem 1: perform systemctl restart mysql_exporter.service Prompt when :
Failed to restart mysql_exporter.service: Unit is not loaded properly: Invalid argument.
See system logs and 'systemctl status mysql_exporter.service' for details.
Check the system log /var/log/messages, Show :
mysql_exporter.service lacks both ExecStart= and ExecStop= settingSo modify mysql_exporter.service, take ExecStart Split to the second line , Save and then execute systemctl restart mysql_exporter.service, Successful implementation .
problem 2: visit prometheus,mysql_reporter The state of is down The state of , Tips :Get "http:// database IP:9104/metrics": context deadline exceeded.

So access the database 9104 port , Access address : database IP:9104, The display is not accessible , View server ports 9104 It's on .

View firewall status :firewall-cmd --state, Display is running.
![]()
So close the firewall :systemctl stop firewalld.service, Then check the firewall status :firewall-cmd --state.
![]()
Refresh Prometheus Interface , Show mysql_reporter yes up state , It means that the monitoring is successful .

problem 3:Grafana Import mysql After the template , No data was obtained .

reason : yes mysqld_exporter Version mismatch , and prometheus.yml File not configured labels.
terms of settlement : take Mysqld_expoter Version USES 11 edition , Just unzip the file before overwriting 12 Version can , Then configure prometheus.yml, Here's the picture :

Save reboot prometheus that will do .
边栏推荐
- Practical application cases of digital Twins - Smart Park
- [waiting for insurance] what does waiting for insurance rectification mean? What are the rectification contents?
- C language programming training topics: K characters in left-handed string, little Lele and Euclidean, printing arrow pattern, civil servant interview, poplar matrix
- Still using xshell? You are out, recommend a more modern terminal connection tool!
- Navicate connects Alibaba cloud (explanation of two methods and principles)
- 分家后印象笔记过日子依然不好过,骚操作却不少
- 微信朋友圈的高性能复杂度分析
- Colleges and universities have introduced 23 Philippine doctors with heavy funds, and the relevant departments have launched an investigation!
- [wechat official account H5] authorization
- Use Matplotlib to simulate linear regression
猜你喜欢

Nearly 30 colleges and universities were named and praised by the Ministry of education!

Iqiyi Tiktok reconciled, Weibo lying gun?

2022 Niuke summer multi school K - link with bracket sequence I (linear DP)
![[wechat official account H5] authorization](/img/d1/2712f87e134c0b8b8fdeaab9e30492.png)
[wechat official account H5] authorization

opencv自带颜色操作

Image information is displayed by browser: data:image/png; Base64, + image content

快速完成intelij idea的单元测试JUnit4设置

Review and analysis of noodle dishes

Three.js (7): local texture refresh

Is computer monitoring true? Four experiments to find out
随机推荐
Today, I met a 38K from Tencent, which let me see the ceiling of the foundation
wallys/IPQ8074A 4x4 2.4G 8x8 5G 802.11ax
ShardingSphere数据库读写分离
hcip第四天笔记
实习报告1——人脸三维重建方法
Openlayers: point aggregation effect
Still using xshell? You are out, recommend a more modern terminal connection tool!
Can CSC open an account for domestic futures? Is it safe?
C language custom type explanation - structure
Development Series III of GaN (lapgan, srgan)
hcip第三天
Eth POS 2.0 stacking test network pledge process
Class bytecode file
es(1)
Get the data of Tongcheng (elong) Hotel
SV强制类型转换和常数
213. 打家劫舍 II-动态规划
pinia 入门及使用
List of stringutils and string methods
portmap 端口转发