Shell scripting counts multiple CPU utilization

Source: Internet
Author: User

The main contents of this section:
Top command to count CPU utilization

One, problem analysis

MySQL is multi-threaded under Linux and can only distribute multiple threads to a single CPU.
Therefore, using a small server, or PC server, multiple CPU utilization is not high.
Basically one or two are in use.

This section shares the statistical CPU utilization method, for everyone to learn the reference.

Related reading:
View Linux system Resource Usage (top, free, uptime)
Detailed explanation of what the top command displays

Second, the Shell script implementation

1. Input TOP-BN1 (b control output format is text format, non-interactive format)

[[Email protected]]$  TOP-BN1

2. Enter top and enter interactive mode to prepare for the next set output format

[[Email protected]]$  

then enter 1

You can view multiple CPU utilization:

Top-21:40:51 up days,  9:32,  1 user,  load average:0.15, 0.30, 0.33tasks:101 Total,   1 running,  96 Sleeping,   0 stopped,   4 zombieCpu0  :  0.8% us,  0.3% sy,  0.0% ni, 98.4% ID,  0.3% wa,  0.0% Hi,  0.0% siCpu1  :  1.1% us,  0.2% sy,  0.0% ni, 98.6% ID,  0.1% wa,  0.0% Hi,  0.0% siCpu2  :  0.5% us,  0.1% sy,  0.0% ni, 99.4% ID,  0.0% wa,  0.0% Hi,  0.0% siCpu3  :  0.4% us,  0.1% sy,  0.0% ni, 99.5% ID,  0.0% wa,  0.0% Hi,  0.0% siCpu4  :  0.3% us,  0.1% sy,  0.0% ni, 99.5% ID,  0.0% wa,  0.0% Hi,  0.0% siCpu5  :  0.3% us,  0.1% sy,  0.0% ni, 99.6% ID,  0.0% wa,  0.0% Hi,  0.0% siCpu6  :  0.3% us,  0.1% Sy,  0.0% NI, 99.6% ID,  0.0% wa,  0.0% Hi,  0.0% siCpu7  :  0.2% us,  0.1% sy,  0.0% ni, 99.7% ID ,  0.0% wa,  0.0% hi,  0.0% si

3. Save parameters for the current output format (configuration output)
Press W on the basis of 2, then press Ctri+c

Save exit
Press Q
(There will be a. toprc file under/home/mysql)

4. Writing the shell program cpu.sh

#!/bin/bashwhile  truedo-bcissn1 >> cpu.log      Ten done

5. Deploying the CPU.SH Program

SH  cpu.sh &

Three. Analysis Log
Cat Cpu.log| grep CPU and other operations, you can analyze the past time, the utilization of each CPU.
Omitted here ..., according to personal interests, output, and even can be output with cacti drawing out.

Four. Delete the configuration file
If you do not want to use the top output format above, you can delete the configuration file

Rm/home/mysql/.toprc  

If you are interested, you can get the contents of cat under. TOPRC.

Shell scripting counts multiple CPU utilization

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.