当前位置:网站首页>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 .
边栏推荐
- Development Series III of GaN (lapgan, srgan)
- 键盘输入操作
- 分家后印象笔记过日子依然不好过,骚操作却不少
- Common questions of testers during interview
- Portfwd port forwarding
- awk从入门到入土(19)awk扩展插件,让awk如虎添翼
- JS & TS learning summary
- Colleges and universities have introduced 23 Philippine doctors with heavy funds, and the relevant departments have launched an investigation!
- 2022 Niuke summer multi school K - link with bracket sequence I (linear DP)
- Two dimensional convolution -- use of torch.nn.conv2d
猜你喜欢

使用matplotlib模拟线性回归

2022 Asia International Internet of things exhibition

C语言自定义类型 — 枚举

Canvas from getting started to persuading friends to give up (graphic version)

分家后印象笔记过日子依然不好过,骚操作却不少

HCNP Routing&Switching之DHCP中继

数论整除分块讲解 例题:2021陕西省赛C

Tensorflow introductory tutorial (40) -- acunet

C语言实现静态版本的通讯录

ShardingSphere数据库读写分离
随机推荐
Common questions of testers during interview
Hcip day 3
C语言自定义类型讲解 — 联合体
Supervisor common commands
Colleges and universities have introduced 23 Philippine doctors with heavy funds, and the relevant departments have launched an investigation!
Niuke linked list solution record
700. Search DFS method in binary search tree
Open source Invoicing system, 10 minutes to complete, it is recommended to collect!
Ipaylinks, a cross-border payment integration service, won the 3A Asia Award of treasury
Keyboard input operation
Step by step introduction to the development framework based on sqlsugar (12) -- split the content of the page module into components to realize the division and rule processing
C语言编程训练题目:左旋字符串中的k个字符、小乐乐与欧几里得、打印箭型图案、公务员面试、杨树矩阵
Logical operation of image pixels
awk从入门到入土(17)awk多行写法
Are the top ten securities companies safe and risky to open accounts?
High performance complexity analysis of wechat circle of friends
2022 Asia International Internet of things exhibition
Huawei machine test - topic core test point
Quickly complete the unit test junit4 setting of intelij idea
通道的分离与合并