I. the Source of the problem is that MySQL is multi-threaded in Linux and can only distribute multiple threads to one CPU. Therefore, in enterprises, the CPU usage of multiple small servers or pcservers is not high. Basically there are 1 ~ Two are in use. This article mainly aims to count the CPU utilization. I hope to attract your attention. 2. program implementation 1. input top-bn1 (B control output format as text format, non-interactive format)
I. source of the problem
MySQL is multi-threaded in Linux and can only distribute multiple threads to one CPU. Therefore, in enterprises, using small servers or PC servers, the utilization of multiple CPUs is not high.
Basically there are 1 ~ Two are in use. This article mainly aims to count the CPU utilization. I hope to attract your attention.
II. program implementation
1. input top-bn1 (B controls the output format as text format, non-interactive format)
[Mysql@longxibendi.host] $ top-bn1
2. enter top to enter the interaction mode and prepare for the next step to set the output format.
[Mysql@longxibendi.host] $ top
Enter 1
You can see multiple CPU utilization.
Top-21:40:51 up 25 days, 1 user, load average: 0.15, 0.30, 0.33
Task: 101 total, 1 running, 96 sleeping, 0 stopped, 4 zombie
Cpu0: 0.8% us, 0.3% sy, 0.0% ni, 98.4% id, 0.3% wa, 0.0% hi, 0.0% si
Cpu1: 1.1% us, 0.2% sy, 0.0% ni, 98.6% id, 0.1% wa, 0.0% hi, 0.0% si
Cpu2: 0.5% us, 0.1% sy, 0.0% ni, 99.4% id, 0.0% wa, 0.0% hi, 0.0% si
Cpu3: 0.4% us, 0.1% sy, 0.0% ni, 99.5% id, 0.0% wa, 0.0% hi, 0.0% si
Cpu4: 0.3% us, 0.1% sy, 0.0% ni, 99.5% id, 0.0% wa, 0.0% hi, 0.0% si
Cpu5: 0.3% us, 0.1% sy, 0.0% ni, 99.6% id, 0.0% wa, 0.0% hi, 0.0% si
Cpu6: 0.3% us, 0.1% sy, 0.0% ni, 99.6% id, 0.0% wa, 0.0% hi, 0.0% si
Cpu7: 0.2% us, 0.1% sy, 0.0% ni, 99.7% id, 0.0% wa, 0.0% hi, 0.0% si
3. save parameters in the current output format (configure output)
Press W on the basis of 2, and then press ctri + c
Save and exit
Press q
(The. toprc file will be available in/home/mysql)
4. write the shell program cpu. sh
#! /Bin/bash
While true
Do
Top-bcisSn1> cpu. log
Sleep 10
Done
5. deploy the cpu. sh program
Sh cpu. sh &
III. log analysis
Cat cpu. log | grep cpu and other operations, you can analyze the past time, the utilization of each cpu.
Here we omit ......, according to personal interests, output, or even use cacti to plot the output.
4. delete the configuration file
If you do not want to use the top output format, you can delete the configuration file.
Rm/home/mysql/. toprc
If you are interested, please refer to the. toprc content.
Author: Phoenix dancer qq: 578989855