In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
Editor to share with you what are the CPU monitoring tools under Linux, I believe most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!
01. Top
Top is the most commonly used tool for viewing the usage of system resources, including CPU, memory, and so on.
The main focus here is on CPU resources.
1.1 / proc/loadavg
Load average is taken from / proc/loadavg.
9.53 9.12 8.37 3/889 28165
The first three numbers are the average number of processes in the process queue in 1, 5, and 15 minutes, including running processes + processes ready to run.
The fourth numerator represents the number of processes running, and the denominator is the total number of processes.
The last number is the ID number of the recently running process.
Where top takes the first three numbers of / proc/loadavg.
1.2 top usage
Open top, and you can specify the update period.
Enter H to open the hidden thread; enter 1 to show the single-core CPU usage.
Top-H-b-d 1-n 200 > top.txt, counted once per second, totaling 200times, showing thread details and saving them to top.txt.
You also rely on / proc/stat and / proc//stat for top sampling sources, which are detailed in / proc/stat [1] and / proc//stat [2].
The meaning of CPU information is as follows:
Us:user, count the user space processes whose nice is less than or equal to 0, that is, the priority is 100,120. Ni:nice, count the user space processes with nice greater than 0, that is, the priority is 121-139. Sys:system, which counts the kernel running time, excluding interrupts. Id:idle, several systems are idle. Wa:iowait, count the waiting time of io. Hi:hardware interrupt, count the hardware interrupt time. Si:software interrupt, count the soft interrupt time. St:steal
02. Perf
Through sudo perf top-s comm, you can see the percentage of processes currently running on the system.
Unlike top, which distinguishes between idle, system, and user, the proportion here is the percentage of each process in the total elapsed time.
Sample information is recorded through sudo perf record, and then through sudo perf report-s comm.
03. Sar and ksar
Sar means System Activity Report and can be used to observe current system activity in real time or to generate historical reports.
To use sar, you need to install sudo apt install sysstat, and then configure sysstat.
Sar is used to record statistical information, and ksar [4] is used to graphically output the recorded information.
The download address for ksar is https://github.com/vlsi/ksar/releases.
# change ENABLED= "false" to ENABLED= "true" $sudo gedit / etc/default/sysstat # modify sar cycle, etc. Configuration $sudo gedit / etc/cron.d/sysstat # restart sar service $sudo / etc/init.d/sysstat restart # sar log storage directory $ls-l / var/log/sysstat/
Use sar to record the statistics from boot to the current file sar.txt.
LC_ALL=C sar-A > sar.txt
PS: sar-An is directly used here and cannot be displayed properly in ksar.
Execute java-jar ksar.jar as follows, and then Data- > Load from text file... Select the saved sar.txt file.
Get the following chart.
You can also record information for a period of time through sar and specify the sampling period and sampling times.
These commands are saved to a file after being preceded by LC_ALL=C, and can be graphically displayed in ksar.
Sar 1 100-Statistics for all cpu all in one sar-P ALL 1 100-including statistics for cpu all in one and individual cpu sar-B 1 100-paging Statistics sar-b 1 100-Block device IO Statistics sar-d 1 100-Block device activity statistics sar-F 1 100-mounted file system statistics sar-r ALL- displays detailed memory usage statistics sar-S- -display swap space usage statistics sar-wmurmuri-display process creation and process switching statistics sar-Wmurmuri-display swap swap in and out statistics.
For more details, please refer to
"How To Create sar Graphs With kSar To Identifying Linux Bottlenecks [5]"
Collect and report Linux System Activity Information with sar [6].
04. Mpstat
Mpstat is Multiprocessor Statistics. When there are no parameters, mpstat displays the average of all information since the system.
The common usage is as follows:-P ALL monitors all CPU, details show that a specific CPU;10 means to monitor every 10 seconds; 20 means to monitor 20 times.
$mpstat-P ALL 10 20
The results are as follows:
Usr represents a user-space process, and nice represents a user-space process with a nice value greater than 0.
Sys is the kernel space, iowait is the IAccord O wait time, irq is the hard interrupt, soft is the soft interrupt, idle is the idle time, guest and gnice are both virtual machine time.
05. Uptime
Uptime is a simple way to get how long the system has been running, and the average load of the last 1 minute, 5 minutes, and 15 minutes.
Uptime gets the relevant information through / proc/uptime and / proc/loadavg.
Before up is the current system time, and after up is the system running time.
After load average, the average load was 1 minute, 5 minutes and 15 minutes.
11:15:41 up 82 days, 20:34, 8 users, load average: 0.28, 0.40, 0.43
06. Vmstat
Vmstat is primarily a tool for monitoring system memory usage, but it also contains some CPU-related information.
Using the method vmstat 5 5 means to run 5 times for 5 seconds each time. The results are as follows:
Procs-memory- swap---io-----system---cpu- r b swpd free buff cache si so bi bo in cs us sy id wa st 10 472576 228688 559092 1061756 00 9 39 10 84 87 00 10 472576 228184 559100 1061756 00 0 13 1532 3395 106 84 00 10 472576 229308 559100 1061616 00 00 1446 3449 10 5 85 00 00 472576 229592 559108 1061616 00 06 1419 3474 10 5 85 00 10 472576 229804 559108 1061616 00 00 1446 3439 10 5 85 00
The above parameters can be divided into six parts: process, memory, swap, io, interrupt and process switching, cpu.
A more detailed explanation:
Reference document: "Linux Performance Measurements using vmstat [7]"
07. Pidstat
Pidstat is mainly used to monitor the consumption of system resources by all or specified processes.
7.1View CPU usage
The first time pidstat runs, it displays statistics from the start of the system, and then running pidstat displays statistics since the last time the command was run. Users can obtain the required statistics by specifying the number and time of statistics.
# displays all process statistics, including idle processes. Pidstat-p ALL # shows thread statistics in more detail. Pidstat-p ALL-t # Periodic sampling and sampling times pidstat [option] interval [count]
In addition, you can get the statistics of the specified process through-p.
Pidstat can also get memory usage statistics with-r and IO usage statistics with-d.
7.2 View memory usage
The results of pidstat-p ALL-r are as follows:
15:18:21 UID PID minflt/s majflt/s VSZ RSS% MEM Command 15:18:21 0 1 0.02 0.00 185316 3028 0.08 systemd 15:18:21 02 0.00 0.00 kthreadd 15:18:21 0 4 0.00. 00 00 0.00 kworker/0:0H 15:18:21 0 6 0.00 0.00 00 0.00 mm_percpu_wq 15:18:21 0 7 0.00 0.00 00 0.00 ksoftirqd/0 15:18:21 0 8 0.00 0 . 00 00 0.00 rcu_sched
Minflt/s: the number of page fault errors per second (minor page faults), which means the number of page fault generated by mapping a virtual memory address to a physical memory address.
Majflt/s: the number of main missing page errors per second (major page faults). When a virtual memory address is mapped to a physical memory address, the corresponding page is in swap. Such page fault is major page fault, which is usually generated when memory usage is tight.
VSZ: the virtual memory (in kB) used by the process.
RSS: the physical memory in kB used by the process.
% MEM: the percentage of memory used by the process.
Command: the command to pull up the process.
7.3 View disk usage
The results of pidstat-p ALL-d are as follows:
15:20:40 UID PID kB_rd/s kB_wr/s kB_ccwr/s iodelay Command 15:20:40 0 1-1.00-1.00-1.00 243523129 systemd 15:20:40 0 2-1.00-1.00-1.00 kthreadd 15:20:40 0 4-1 .00-1.00-1.00 kworker/0:0H 15:20:40 0 6-1.00-1.00-1.00 mm_percpu_wq 15:20:40 0 7-1.00-1.00-1.00 714512328679 ksoftirqd/0 15:20:40 0 8-1.00 -1.00-1.00 417757303594 rcu_sched
KB_rd/s: the amount of data (in kB) that the process reads from disk per second.
KB_wr/s: the amount of data (in kB) that the process writes to disk per second.
KB_ccwr/s: the amount of data written to disk by the process per second (in kB).
Command:: pulls up the corresponding command for the process.
08. Time
The time command can be used to count the CPU time of a specified program.
For example, time cksum nomachine_6.0.80_1.exe gets the following results.
2401940638 32606752 nomachine_6.0.80_1.exe # the whole operation takes time, 00.263-0.094-0.011mm 0.158 is the IO waiting time. Real 0m0.263s # user mode time consuming user 0m0.094s # kernel state time consuming sys 0m0.011s 2401940638 32606752 nomachine_6.0.80_1.exe # the second execution shows that the time to wait for the IO operation is basically gone. Real 0m0.098s user 0m0.097s sys 0m0.000s
09. Cpustat
With sudo apt install cpustat installation, the result of cpustat-T-D-x is as follows.
# display Load Avg information and average frequency, such as Load Avg 0.66 0.54 0.49, Freq Avg. 1.46 GHz, 4 CPUs online # process switching times, hard interrupts, soft interrupts and other statistics. # CPU occupancy, user space and kernel space occupancy, etc. 3791.1 Ctxt/s, 1709.9 IRQ/s, 1800.0 softIRQ/s, 0.0 new tasks/s, 1 running 0 blocked% CPU% USR% SYS PID S CPU Time Task 25.74 25.74 0.00 11435 R 3 2.29w / usr/bin/python3 15.84 15.84 0.00 9445 S 0 1.49w / usr/lib/xorg/Xorg 10.89 9.90 0.99 2722 S 1 1.05w compiz 7.92 0.00 7.92 32352 S 2 16.60s [kworker/2:1] 0.990.00 0.99 32397 R 1 0.01s cpustat 0.99 0.99 0.00 11046 S 2 16.20h compiz 0.99 0.99 0.00 1317 S 0 8.76h / usr/NX/bin/nxnode.bin 0.99 0.00 0.99 10293 S 1 1.24m [kworker/1:2] 64.36 53.47 10.89 Total Load Avg 0.66 0.54 0.49 Freq Avg. 1.75 GHz, 4 CPUs online 2834.8 Ctxt/s, 1190.9 IRQ/s, 1183.3 softIRQ/s, 0.0 new tasks/s, 4 running 0 blocked% CPU% USR% SYS PID S CPU Time Task 25.76 25.76 0.00 11435 R 3 2.29w / usr/bin/python3 18.18 18.18 0.00 9445 S 0 1.49w / usr/lib/xorg/Xorg 7.58 7.58 0.00 2722 S 1 1.05w compiz 6.06 6.06 32352 S 2 16.64s [kworker/2:1] 1.52 0.00 1.52 32397 R 1 0.02s cpustat 1.52 0.00 8 S 0 3.00h [rcu_sched] 1.52 0.00 1.52 18409 S 0 1.16m update-notifier 62.1251.52 10.61 Total Distribution of CPU utilisation (per Task):% CPU Utilisation Count (%) 0.00-1.97 706 98.88 1.97-3.94 0 0.00 3.94-5.91 0 0.00 5.91-7.88 2 0.28 7.88-9.85 0 0.00 9.85-11.82 0 0.00 11.82-13.79 1 0.14 13.79-15.76 0 0.00 15.76-17.73 1 0.14 17 .73-19.70 1 0.14 19.70-21.67 0 0.00 21.67-23.64 0 0.00 23.64-25.61 2 0.28 25.61-27.57 0 0.00 27.58-29.54 0 0.00 29.55-31.51 0 0.00 31. 52-33.48 0 0.00 33.48-35.45 0 0.00 35.45-37.42 0 0.00 37.42-39.39 1 0.14 Distribution of CPU utilisation (per CPU):-occupancy rate of each CPU Divided into user space and kernel space. CPU# USR% SYS% 0 17.37 1.20 1 8.98 2.40 2 0.60 7.19 3 25.75 0.00
10. Htop
Htop and top have similar functions, but are more readable than top. Press F5 in the interface, you can see the threads in the process, and the tree structure represents the parent-child relationship.
11. Atop
Atop is a tool for monitoring system resources and processes. It sorts the processes in the list in descending order by CPU utilization, and each process contains information such as CPU, memory, disk, and network status. Its function is similar to top and htop.
12. Glances
Glances is a reporting tool written by python that is similar to Nmon and can report statistics on cpu, memory, network, disk, and processes. Apart from reporting statistics, glances does not support any other features or functions. Click "h" while the program is running to display the help page.
13. Nmon
Nmon is a very easy-to-use tool that monitors CPU, memory, network, disk usage, and process lists on a single screen. Except that you cannot manage the process and modify the report display, Nmon is exactly the same as those reporting tools that are only used for reporting. In addition, it can save data to a spreadsheet file.
14. PCP-gui
Performance Co-Pilot, referred to as PCP, is a system performance and analysis framework. It collates data from multiple hosts and analyzes them in real time to help you identify abnormal performance patterns. It also provides API for you to design your own monitoring and reporting solutions.
Install PCP related tools.
$sudo apt install PCP PCP-gui
File- > Open View select the view you want to open, such as CPU, Disk, Memory, and so on.
15. Collectl and colplot
15.1 collectl use
Collectl is an excellent utility with rich command-line features that you can use to collect performance data that describe the current state of the system.
Unlike most other system monitoring tools, collectl is not limited to limited system metrics. On the contrary, it can collect information about many different types of system resources, such as cpu, disk, memory, network, sockets, tcp, inodes, infiniband, lustre, memory, nfs, processes, quadrics, slabs and buddyinfo.
At the same time, collectl can also replace common tools, such as top, vmstat, ps, iotop and so on.
Install collectl:
Sudo apt-get install collectl
The use of collectl is simple, and the default collectl displays cpu, disk, and network information.
Collectl can also display more subsystem information, and if the option has a corresponding uppercase option, the uppercase option represents more detailed device statistics.
B-buddy info (memory fragmentation) c-uniform statistics for all CPU; C-statistics for a single CPU. D-Disk all-in-one statistics for the entire file system; C-statistics for a single disk. F-NFS V3 Data I-Inode and File System j-shows the Interrupts trigger for each CPU; J-shows the detailed trigger for each interrupt. L-Lustre m-shows the Memory usage of the entire system; M-displays memory usage by node. N-shows the Networks usage of the whole system; N-sub card shows the network usage. S-Sockets t-TCP x-Interconnect y-use statistics for all Slabs (system object cache) of the system; Y-details of each slab usage.
Collectl-all displays statistics for all subsystems, including cpu, terminal, memory, disk, network, TCP, socket, file system, NFS.
Collectl-- top can replace the top command:
Collectl-- vmstat can replace the vmstat command:
Collectl-C1-sZ-ips 1 can be used instead of the ps command.
The combination of collectl and some tools for processing and analyzing data (such as colmux, colgui, colplot) can provide visual graphics.
15.2 colplot use
Colplot is part of the collectl toolset that graphically displays the data collected by collectl in the browser.
Introduction to colplot (http://collectl-utils.sourceforge.net/colplot.html), related source code can be downloaded from collectl-utils): https://sourceforge.net/projects/collectl-utils/files/
After unpacking the downloaded colplot, sudo. / INSTALL installs colplot.
Restart the apache service after installation:
$suod systemctl reload apache2 $sudo systemctl restart apache2
Enter http://127.0.0.1/colplot/ in the browser to use colplot.
Choose to store the data saved by collectl-P through Change Dir, and then set the Plot details, display those subsystems, plot size, and so on.
Finally, Generate Plot looks at the results.
The above is all the contents of the article "what are the CPU monitoring tools under Linux". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.