Linux mpstat command-Report processor statistics

Source: Internet
Author: User

Currently, most computers use multi-processor or quad-core single processor. On the server side, more processors or cores mean stronger capabilities, but on the other hand, applications also require higher energy consumption. You may have encountered such a scenario: when your cpu usage is very high, you feel that you have not run any program at all. In Linux, you can use mpstate to monitor such activities.

Install iostat and mpstat

Mpstat

What is mpstat?

Mpstat is used to monitor the cpu usage on your system. If your system has multiple processors, it will play a greater role. The first processor is marked as CPU 0. The second one will be marked as CPU 2, and so on. Mpstat is described as follows in the operation manual:

The mpstat command writes the status of each available processor to the standard output. The first processor is 0 by default. The global average status of all processors is also reported. The mpstat command can be used on SMP and UP machines, but on the UP machine, only the global average status is printed out. If no specific behavior is selected, the CPU usage is reported by default.

How to run mpstat

You only need to enter mpstat on your terminal to run mpstat.

$ mpstatLinux 3.2.0-57-generic (USERNB01) 12/12/2013 _x86_64_ (2 CPU)03:29:29 PM CPU %usr %nice %sys %iowait %irq %soft %steal %guest %idle03:29:29 PM all 6.30 0.06 1.94 3.75 0.00 0.06 0.00 0.00 87.88

If you find that, for example, the command cannot be found or a similar error occurs, you may not have installed mpstat.

If you are using CentOS, RedHat or Fedora, run the following command to install mpstat:

# yum install sysstat

If you are using Debian, Ubuntu or its derivative version, run the following command to install mpstat

# apt-get install sysstat

The following describes how to understand the information shown above.

  • 03:29:29: the time when mpstat runs.
  • All: all CPUs
  • % Usr: displays the percentage of CPU utilization during user-level (such as application) Execution
  • % Nice: displays the percentage of CPU usage during user-level execution with nice priority
  • % Sys: Percentage of CPU utilization during actual execution at the system level (such as the kernel)
  • % Iowait: displays the percentage of CPU idle time during an incomplete disk I/O Request.
  • % Irq: display the percentage of time spent on hardware interruption of CPU Service
  • % Soft: displays the percentage of CPU service software interruption time
  • % Steal: displays the percentage of time spent by the Virtual Machine manager when serving another virtual processor.
  • % Guest: displays the percentage of CPU time spent when a virtual processor is running.
  • % Idle: displays the percentage of time when the CPU is idle and there are no unfinished disk I/O requests.
Print the CPU usage of each processor

As shown in the preceding command results, our system has two CPUs. If you want to, you can use the-P Parameter followed by the CPU number to get the specified CPU utilization.

$ mpstat -P 0Linux 3.2.0-57-generic (USERNB01) 12/12/2013 _x86_64_ (2 CPU)03:54:00 PM CPU %usr %nice %sys %iowait %irq %soft %steal %guest %idle03:54:00 PM 0 3.82 0.01 1.16 3.88 0.00 0.06 0.00 0.00 91.06$ mpstat -P 1Linux 3.2.0-57-generic (USERNB01) 12/12/2013 _x86_64_ (2 CPU)03:53:58 PM CPU %usr %nice %sys %iowait %irq %soft %steal %guest %idle03:53:58 PM 1 16.52 0.20 4.48 0.46 0.00 0.04 0.00 0.00 78.30
Print the utilization of all CPUs

You can also print the CPU usage of each processor on a page, which is specified by the-p all parameter.

$ mpstat -P ALLLinux 3.2.0-57-generic (USERNB01) 12/12/2013 _x86_64_ (2 CPU)04:07:36 PM CPU %usr %nice %sys %iowait %irq %soft %steal %guest %idle04:07:36 PM all 6.02 0.04 1.72 2.99 0.00 0.05 0.00 0.00 89.1704:07:36 PM 0 3.84 0.01 1.15 3.72 0.00 0.06 0.00 0.00 91.2104:07:36 PM 1 13.55 0.15 3.66 0.46 0.00 0.03 0.00 0.00 82.15
Use time interval to print CPU usage

If you want to observe CPU utilization changes, you can use the interval. The following is an example.

$ mpstat 3 4Linux 3.2.0-57-generic (USERNB01) 12/12/2013 _x86_64_ (2 CPU)04:27:11 PM CPU %usr %nice %sys %iowait %irq %soft %steal %guest %idle04:27:14 PM all 0.67 0.00 0.34 0.00 0.00 0.00 0.00 0.00 98.9904:27:17 PM all 1.17 0.00 0.33 1.33 0.00 0.00 0.00 0.00 97.1704:27:20 PM all 0.84 0.00 0.17 0.00 0.00 0.00 0.00 0.00 98.9904:27:23 PM all 1.00 0.00 0.17 1.51 0.00 0.00 0.00 0.00 97.32Average: all 0.92 0.00 0.25 0.71 0.00 0.00 0.00 0.00 98.12

The preceding command displays four CPU utilization reports every three seconds.

Print the mpstat version

Finally, to print the mpstat version, use the-V parameter.

$ mpstat -Vsysstat version 10.0.3(C) Sebastien Godard (sysstat orange.

This is how to quickly use mpstat on linux. For more details, enter man mpstat to view the mpstat manual.

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.