YouTip LogoYouTip

Linux Comm Mpstat

[![Image 1: Linux Command Encyclopaedia](#) Linux Command Encyclopaedia](#)\\n\\n* * *\\n\\n## 1. mpstat Command Overview\\n\\nmpstat (Multi-Processor Statistics) is a performance monitoring tool in Linux systems, part of the sysstat package. It is mainly used to monitor CPU usage and can display detailed statistics for each CPU core.\\n\\n### 1.1 Main Features\\n\\n* Display detailed statistics of CPU usage\\n* Monitor performance of individual CPU cores or all cores\\n* Provide CPU time percentage for user mode, kernel mode, idle state, etc.\\n* Support interval sampling and multiple sampling\\n\\n### 1.2 Applicable Scenarios\\n\\n* System performance tuning\\n* CPU bottleneck analysis\\n* Multi-core CPU load balancing check\\n* System monitoring and troubleshooting\\n\\n* * *\\n\\n## 2. Installation and Basic Usage\\n\\n### 2.1 Installation Methods\\n\\nMost Linux distributions can install via package manager:\\n\\n# Ubuntu/Debian\\nsudo apt install sysstat\\n# CentOS/RHEL\\nsudo yum install sysstat\\n# Arch Linux\\nsudo pacman -S sysstat\\n\\n### 2.2 Basic Command Format\\n\\nmpstat \\n\\n#### Simple Examples\\n\\n## Examples\\n\\n# Display current statistics for all CPU cores\\n\\nmpstat\\n\\n# Sample once every 2 seconds, for a total of 5 times\\n\\nmpstat 2 5\\n\\n* * *\\n\\n## 3. Command Options Explained\\n\\n| Option | Description |\\n| --- | --- |\\n| -P {ALL|CPUID} | Specify CPU core to display (ALL means all cores) |\\n| -u | Display CPU usage rate (default option) |\\n| -I {SUM|CPU|SCPU|ALL} | Display interrupt statistics |\\n| -V | Display version information |\\n| -o JSON | Output results in JSON format |\\n\\n### 3.1 Common Option Combinations\\n\\n## Examples\\n\\n# Monitor all CPU cores, refresh every 1 second\\n\\nmpstat -P ALL 1\\n\\n# Monitor only the first CPU core (CPU0)\\n\\nmpstat -P 0 1 5\\n\\n* * *\\n\\n## 4. Output Result Analysis\\n\\nTypical output of executing `mpstat -P ALL 1`:\\n\\nLinux 5.4.0-91-generic (hostname) 03/15/2023 _x86_64_ (4 CPU)\\n10:30:45 AM CPU %usr %nice %sys %iowait %irq %soft %steal %guest %gnice %idle\\n10:30:46 AM all 5.25 0.00 1.25 0.25 0.00 0.25 0.00 0.00 0.00 93.00\\n10:30:46 AM 0 6.00 0.00 1.00 0.00 0.00 0.00 0.00 0.00 0.00 93.00\\n10:30:46 AM 1 4.00 0.00 1.00 1.00 0.00 1.00 0.00 0.00 0.00 93.00\\n10:30:46 AM 2 6.00 0.00 2.00 0.00 0.00 0.00 0.00 0.00 0.00 92.00\\n10:30:46 AM 3 5.00 0.00 1.00 0.00 0.00 0.00 0.00 0.00 0.00 94.00\\n\\n### 4.1 Field Meanings\\n\\n| Field | Description |\\n| --- | --- |\\n| %usr | Percentage of CPU time in user mode |\\n| %nice | Percentage of CPU time for low-priority user mode programs |\\n| %sys | Percentage of CPU time in kernel mode |\\n| %iowait | Percentage of CPU time waiting for I/O operations |\\n| %irq | Percentage of CPU time handling hardware interrupts |\\n| %soft | Percentage of CPU time handling software interrupts |\\n| %steal | Percentage of time virtual CPU waits for physical CPU |\\n| %guest | Percentage of time running virtual processors |\\n| %gnice | Percentage of time running low-priority guests |\\n| %idle | Percentage of CPU idle time |\\n\\n* * *\\n\\n## 5. Practical Application Cases\\n\\n### 5.1 Monitoring CPU Usage\\n\\n## Examples\\n\\n# Monitor all CPU cores, refresh every 2 seconds, display 5 times\\n\\nmpstat -P ALL 2 5\\n\\n### 5.2 Identifying CPU Bottlenecks\\n\\nFocus on:\\n\\n* High %usr: User mode programs consuming large amounts of CPU\\n* High %sys: Frequent system calls\\n* High %iowait: Possible I/O bottleneck\\n\\n### 5.3 Generating Performance Reports\\n\\n## Examples\\n\\n# Redirect output to file\\n\\nmpstat -P ALL 1 60 > cpu_stats.log\\n\\n* * *\\n\\n## 6. Frequently Asked Questions\\n\\n### 6.1 What is the difference between mpstat and top commands?\\n\\n* `top`: Real-time dynamic display of overall system status\\n* `mpstat`: Focuses on CPU statistics, providing more detailed per-core data\\n\\n### 6.2 What does low %idle indicate?\\n\\nIt means the CPU is busy; need to combine with other indicators:\\n\\n* If %usr is high: Applications consuming large amounts of CPU\\n* If %sys is high: Too many system calls\\n* If %iowait is high: I/O has become a bottleneck\\n\\n### 6.3 How to monitor specific CPU cores?\\n\\n## Examples\\n\\n# Monitor only CPU core 2\\n\\nmpstat -P 2 1\\n\\n* * *\\n\\n## 7. Summary\\n\\nmpstat is an important tool for Linux system performance monitoring, especially suitable for analyzing multi-core CPU usage. After studying this article, you should be able to:\\n\\n1. Understand the basic principles and use cases of mpstat\\n2. Master common command options of mpstat\\n3. Correctly interpret mpstat output results\\n4. Apply mpstat for performance analysis in actual work\\n\\nIt is recommended to use it together with other tools like `vmstat` and `iostat` for more comprehensive analysis of system performance issues.\\n\\n[![Image 2: Linux Command Encyclopaedia](#) Linux Command Encyclopaedia](#)
← Linux Comm Lsb_ReleaseLinux Comm Vmstat β†’