Display CPU utilization
Need sysstat package.
If we are using SMP (Multiple CPU) system, use mpstat command to display the utilization of each CPU individually.
The mpstat command display activities for each available processor, processor 0 being the first one. Global average activities among all processors are also reported. The mpstat command can be used both on SMP and UP machines, but in the latter, only global average activities will be printed.
mpstat mpstat -P ALL
mpstat -P ALL 5 2
It shows the various stats for the CPUs in the system. The –P ALL options directs the command to display stats for all the CPUs, not just a specific one. The parameters 5 2 directs the command to run every 5 seconds and for 2 times. The above output shows the metrics for all the CPUs first (aggregated) and for each CPU individually. Finally, the average for all the CPUs has been shown at the end.
The '%user' column indicates the percentage of the processing for that CPU consumes by user processes. User processes are non-kernel processes used for applications such as an Oracle database. In this example output, the user CPU %age is very little.
The '%nice' column indicates the percentage of CPU when a process was downgraded by nice command. The command nice has been described in an earlier installment. It brief, the command nice changes the priority of a process.
The '%system' column indicates the CPU percentage consumed by kernel processes
The '%iowait' column shows the percentage of CPU time consumed by waiting for an I/O to occur
The '%irq' column indicates the % of CPU used to handle system interrupts
The '%soft' column indicates % consumed for software interrupts
The '%idle' column shows the idle time of the CPU
The '%intr/s' column shows the total number of interrupts received by the CPU per second
You may be wondering about the purpose of the mpstat command when you have vmstat, described earlier. There is a huge difference: mpstat can show the per processor stats, whereas vmstat shows a consolidated view of all processors. So, it’s possible that a poorly written application not using multi-threaded architecture runs on a multi-processor machine but does not use all the processors. As a result, one CPU overloads while others remain free. You can easily diagnose these sorts of issues via mpstat.