Monitoring CPU performance is crucial for understanding the overall system performance. Here's a guide on how to monitor CPU performance in CentOS:
- Using Command-Line Tools: CentOS, being a Linux distribution, offers various command-line tools to monitor CPU performance. Some of the commonly used tools include:
- `top`: Displays real-time information about CPU usage, memory usage, running processes, etc.
- `mpstat`: Part of the sysstat package, it provides detailed CPU usage statistics for each processor or processor core.
- `sar`: A utility for managing system resources, including CPU performance, which can be tracked using the -u option.
- `iostat`: Shows average CPU usage and input/output load (disk read/write activity).
- `lscpu`: Provides detailed CPU information such as the number of CPU cores, architecture, and virtualization support.
- Using Third-Party Tools: In addition to command-line tools, there are third-party applications that provide graphical interfaces for monitoring CPU performance, such as:
- GNOME System Monitor: A built-in graphical monitoring tool in Ubuntu that allows you to monitor tasks and CPU usage.
- Netdata: An open-source, real-time monitoring tool that provides easy-to-interpret charts and graphs for CPU usage, RAM usage, bandwidth statistics, and disk utilization. It also offers basic authentication and can be secured with Nginx as a reverse proxy.
What You'll Learn
Use the 'top' command to view CPU load
The top command is a performance monitoring program that displays all the running and active real-time processes in an ordered list and updates it regularly. It also shows high memory and CPU utilisation of running processes.
To use the top command, open a terminal window and enter the following command:
Top
The system will respond by displaying a list of all the processes that are currently running. It also shows users, tasks, CPU load, and memory usage. This list changes frequently as background tasks start and complete. To remedy this, enter top with the -i option:
Top -i
The system will hide all the idle processes, making it easier to sort through the list.
To quit the top function, press q.
While top is running, you can use the following commands:
- M: sort the task list by memory usage.
- P: sort the task list by processor usage.
- N: sort the task list by process ID.
- T: sort the task list by run time.
To get assistance with top, press h while the tool is running. Or, you can enter the following at the command line:
Man top
This command displays the manual page for the top command.
The top command mostly works the same across all Linux distributions, although there are some variants that may display the information differently – for example, in a different order.
The first line of the display shows the system time, system uptime (how long since the last reboot), number of active user sessions, and the system's load average. The load average is particularly relevant as it sheds some light on the system's CPU usage over time.
There are three numbers given for the load average. The numbers are the average load over 1, 5, and 15 minutes, respectively. Think of these numbers as percentages – a load of 0.2 means 20%, and a load of 1.00 means 100%.
The second line of top displays the number of tasks running on the system and their current state.
The third line is where we find our CPU usage, with some detailed statistics that take a little knowledge to interpret:
- Us: Percentage of CPU time spent in user space (running user-spawned processes).
- Sy: Percentage of CPU time spent in kernel space (running system processes).
- Ni: Percentage of CPU time spent on running processes with a user-defined priority (a specified nice value).
- Id: Percentage of CPU time spent idle.
- Wa: Percentage of CPU time spent on waiting on I/O from hardware. For example, waiting for a hard drive to finish reading data.
- Hi: Percentage of CPU time spent processing hardware interrupts. For example, the network card (or any piece of hardware) interrupting the CPU to notify it that new data has arrived.
- Si: Percentage of CPU time spent processing software interrupts. For example, a high-priority service interrupting the CPU.
- St: Percentage of CPU time that was stolen from a virtual machine. For example, the CPU needed to "steal" resources from a virtual machine in order to process the physical machine's workload.
The next two lines are dedicated to memory information and aren't relevant for monitoring CPU usage. Below that, there's a list of running processes and a column titled %CPU, which contains the current CPU usage of each process listed.
Healthcare Performance Monitoring: Strategies for Success
You may want to see also
Use the 'mpstat' command to display CPU activity
The mpstat command is used to display CPU activity and is part of a software bundle called sysstat, which is included in most RHEL-based distributions.
To install the sysstat package on Debian and Ubuntu systems, use the following command:
Sudo apt install sysstat
Once the process is complete, enter the mpstat command:
Mpstat
The system will then display the usage for each processor or processor core.
The first line is a set of column labels, and the second line is the value for each column:
- %usr - % CPU usage at the user level
- %nice - % CPU usage for user processes labelled "nice"
- %sys - % CPU usage at the system (Linux kernel) level
- %iowait - % CPU usage idling, waiting on a disk read/write
- %irq - % CPU usage handling hardware interrupts
- %soft - % CPU usage handling software interrupts
- %steal - % CPU usage being forced to wait for a hypervisor handling other virtual processors
- %guest - % CPU usage spent running a virtual processor
- %idle - % CPU usage on idle time (no processes and not waiting on a disk read/write)
You can also specify a single processor to report on by using the -P switch:
Mpstat -P 0
This will display a report for the first processor (CPU 0).
To show total statistics and list processes by individual CPU, use the ALL option:
Mpstat -P ALL
By default, the mpstat command only takes a snapshot of CPU usage. To take a series of snapshots, indicate an interval and the number of reports:
Mpstat 7 5
This command will generate 7 snapshots, each 5 seconds apart, and calculate average values.
LCD Monitors: Unveiling the Myths and Misconceptions
You may want to see also
Use the 'sar' command to show CPU utilisation
The sar command is a utility for managing system resources and monitoring CPU performance. It is not limited to CPU usage, but you can use the -u option to track CPU performance.
To direct sar to monitor CPU usage at set intervals, enter the following command:
Bash
Sar -u 5
The -u option displays CPU usage, and the number 5 indicates that it should display every 5 seconds.
To cancel the command, press Ctrl+C.
You can also use the sar command to display CPU usage by CPU or core:
Bash
Sar -P ALL
The -P ALL flag indicates that you want to display statistics for all of the individual cores.
If you want to display statistics for only one core, use the -P flag followed by the core number, as shown in the following example:
Bash
Sar -P 1
Hooking Up Three Monitors: The Ultimate Guide for a Super-Sized Setup
You may want to see also
Use the 'iostat' command for average CPU usage
The iostat command is used to monitor system input/output device loading by observing the time the devices are active in relation to their average transfer rates. The iostat command generates two types of reports: the CPU Utilization report and the Device Utilization report.
CPU Utilization Report
The first report generated by the iostat command is the CPU Utilization Report. For multiprocessor systems, the CPU values are global averages among all processors. The report has the following format:
- %user: The percentage of CPU utilization that occurred while executing at the user level (application).
- %nice: The percentage of CPU utilization that occurred while executing at the user level with nice priority.
- %system: The percentage of CPU utilization that occurred while executing at the system level (kernel).
- %iowait: The percentage of time that the CPU or CPUs were idle during which the system had an outstanding disk I/O request.
- %steal: The percentage of time spent in involuntary wait by the virtual CPU or CPUs while the hypervisor was servicing another virtual processor.
- %idle: The percentage of time that the CPU or CPUs were idle and the system did not have an outstanding disk I/O request.
Device Utilization Report
The second report generated by the iostat command is the Device Utilization Report. The device report provides statistics on a per physical device or partition basis. The report may show the following fields, depending on the flags used:
- Device: The device (or partition) name as listed in the /dev directory.
- Tps: The number of transfers per second that were issued to the device.
- Blk_read/s: The amount of data read from the device expressed in a number of blocks (kilobytes, megabytes) per second.
- Blk_wrtn/s: The amount of data written to the device expressed in a number of blocks (kilobytes, megabytes) per second.
- Blk_read: The total number of blocks read.
- Blk_wrtn: The total number of blocks written.
- Blk_dscd/s: The amount of data discarded for the device expressed in a number of blocks (kilobytes, megabytes) per second.
- Blk_w+d/s: The amount of data written to or discarded for the device expressed in a number of blocks (kilobytes, megabytes) per second.
- R/s: The number of read requests completed per second for the device.
- W/s: The number of write requests completed per second for the device.
- D/s: The number of discard requests completed per second for the device.
- F/s: The number of flush requests completed per second for the device.
- Sec/s: The number of sectors (kilobytes, megabytes) read from, written to or discarded for the device per second.
- Rsec/s: The number of sectors (kilobytes, megabytes) read from the device per second.
- Wsec/s: The number of sectors (kilobytes, megabytes) written to the device per second.
- Dsec/s: The number of sectors (kilobytes, megabytes) discarded for the device per second.
- Rqm/s: The number of I/O requests merged per second that were queued to the device.
- Rrqm/s: The number of read requests merged per second that were queued to the device.
- Wrqm/s: The number of write requests merged per second that were queued to the device.
- Drqm/s: The number of discard requests merged per second that were queued to the device.
- %rrqm: The percentage of read requests merged together before being sent to the device.
- %wrqm: The percentage of write requests merged together before being sent to the device.
- %drqm: The percentage of discard requests merged together before being sent to the device.
- Areq-sz: The average size (in kilobytes) of the I/O requests that were issued to the device.
- Rareq-sz: The average size (in kilobytes) of the read requests that were issued to the device.
- Wareq-sz: The average size (in kilobytes) of the write requests that were issued to the device.
- Dareq-sz: The average size (in kilobytes) of the discard requests that were issued to the device.
- Await: The average time (in milliseconds) for I/O requests issued to the device to be served.
- R_await: The average time (in milliseconds) for read requests issued to the device to be served.
- W_await: The average time (in milliseconds) for write requests issued to the device to be served.
- D_await: The average time (in milliseconds) for discard requests issued to the device to be served.
- F_await: The average time (in milliseconds) for flush requests issued to the device to be served.
- Aqu-sz: The average queue length of the requests that were issued to the device.
- %util: The percentage of elapsed time during which I/O requests were issued to the device (bandwidth utilization for the device).
Examples of iostat command usage:
- Iostat -x: Show more detailed statistics information.
- Iostat -c: Show only the CPU statistic.
- Iostat -d: Display only the device report.
- Iostat -xd: Show extended I/O statistic for device only.
- Iostat -k: Capture the statistics in kilobytes or megabytes.
- Iostat -k 2 3: Display CPU and device statistics with delay.
- Iostat -j ID mmcbkl0 sda6 -x -m 2 2: Display persistent device name statistics.
- Iostat -p: Display statistics for block devices.
- Iostat -N: Display LVM2 statistic information.
- Iostat -xdm --human 2: Extended device statistics in a human-readable format updated every 2 seconds indefinitely.
Monitor Internet Usage: Airport Extreme Settings Guide
You may want to see also
Use the 'lscpu' command to get detailed CPU information
The lscpu command is a command-line utility in Linux that is used to get detailed CPU information about the system. It fetches the CPU architecture information from the sysfs and /proc/cpuinfo files and displays it in a terminal.
The command returns a large amount of general CPU information, including the number of CPU cores, CPU architecture, CPU usage, and more. Here are some examples of the information that can be obtained using the lscpu command:
- CPU make and model
- Number of sockets
- Number of CPU cores
- Threads per core
- Total threads
- Virtualization support
- CPU vendor ID
- CPU family and model
- CPU speed
- CPU cache size
To get a specific set of information, additional arguments can be implemented to weed out unnecessary details. For example, to only get information about the CPU make and model, number of sockets, number of CPU cores, threads per core, and total threads, you can use the following command:
Bash
Lscpu | egrep 'Model name|Socket|Thread|NUMA|CPU/(s/)'
This will return an output that is easier to read and use.
The lscpu command can also be used to check if the CPU supports virtualization. By piping the command through grep and checking for the Virtualization flag, you can determine if the CPU is enabled for virtualization. The command for this is:
Bash
Lscpu | grep 'Virtualization'
If the output includes "VT-x", then the CPU supports virtualization. If VT-x is not listed, a different machine must be used.
Overall, the lscpu command is a powerful tool for gathering detailed information about the CPU in a Linux system. It provides a comprehensive overview of the CPU architecture, usage, and performance, making it an essential tool for system administrators and users who need to monitor and troubleshoot their systems.
Removing Monitor Heater Flue Pipes: A Step-by-Step Guide
You may want to see also