当前位置:网站首页>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 .
边栏推荐
- C language custom type explanation - structure
- Iqiyi Tiktok reconciled, Weibo lying gun?
- [wechat official account H5] authorization
- C语言自定义类型 — 枚举
- opencv自带颜色操作
- 获取同程(艺龙)酒店数据
- Wallys/3 × 3/2 × 2 MIMO 802.11ac Mini PCIe Wi-Fi Module, Dual Band, 2,4GHz / 5GHz/QCN9074
- 快速完成intelij idea的单元测试JUnit4设置
- Opencv has its own color operation
- DHCP relay of HCNP Routing & Switching
猜你喜欢

opencv自带颜色操作

2022 牛客暑期多校 K - Link with Bracket Sequence I(线性dp)

【网络安全】网站中间件存在的解析漏洞

使用matplotlib模拟线性回归

NC port forwarding

Tensorflow introductory tutorial (40) -- acunet
How to remove the top picture of the bubble skin article details of solo blog

ansible自动化运维详解(五)ansible中变量的设定使用、JINJA2模板的使用以及ansible的加密控制

Two dimensional convolution -- use of torch.nn.conv2d

2022 Niuke summer multi school K - link with bracket sequence I (linear DP)
随机推荐
CDN (content delivery network) content distribution network from entry to practice
Portfwd port forwarding
Wallys/3 × 3/2 × 2 MIMO 802.11ac Mini PCIe Wi-Fi Module, Dual Band, 2,4GHz / 5GHz/QCN9074
C语言自定义类型讲解 — 结构体
Use Matplotlib to simulate linear regression
C language custom type explanation - structure
[wechat official account H5] authorization
Ipaylinks, a cross-border payment integration service, won the 3A Asia Award of treasury
Canvas from getting started to persuading friends to give up (graphic version)
干货|值得收藏的三款子域名收集工具
Image information is displayed by browser: data:image/png; Base64, + image content
awk从入门到入土(17)awk多行写法
How to remove the top picture of the bubble skin article details of solo blog
Tensorflow introductory tutorial (37) -- DC Vnet
wallys/IPQ8074A 4x4 2.4G 8x8 5G 802.11ax
通道的分离与合并
Iqiyi Tiktok reconciled, Weibo lying gun?
Tensorflow introductory tutorial (38) -- V2 net
C语言中的字符与字符串库函数的使用以及模拟实现
Separation and merging of channels