In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces how to install and use cpustat under Linux. It is very detailed and has a certain reference value. Friends who are interested must finish it!
Cpustat is a system performance measurement program written in Go under Linux. It displays CPU utilization and saturation in an effective way by using the method for analyzing the performance of any system (USE).
It samples every process running in the system at a high frequency and then aggregates these samples at a lower frequency. For example, it can measure each process every 200ms and then summarize these samples every 5 seconds, including the minimum / average / maximum value (min/avg/max) of some metrics.
How to install cpustat in Linux
In order to use cpustat, you must have Go language (GoLang) installed on your Linux system. If you have not already installed it, click the link below to install GoLang step by step:
Install GoLang (Go programming language) under Linux
After installing Go, type the following go get command to install cpustat, which installs the cpustat binaries to your GOBIN variable (the path you refer to):
# how go get github.com/uber-common/cpustat uses cpustat in Linux
After the installation process is complete, if you do not control the system as a root user, use the sudo command to obtain root permission to run cpustat as follows, otherwise the error message shown below will appear:
$GOBIN/cpustatThis program uses the netlink taskstats interface, so it must be run as root.
Note: to run cpustat like other Go programs already installed on your system, you need to add the GOBIN variable to the PATH environment variable. Open the link below to learn how to set the PATH variable in Linux.
Cpustat works like this: query the / proc directory at each interval to get the current process ID list, and then:
For each PID, read / proc/pid/stat, and then calculate the difference from the previous sample. If it is a new PID, read / proc/pid/cmdline. For each PID, send a netlink message to get the taskstat, calculating the difference from the previous sample. Read / proc/stat to get total system statistics.
Each break interval is adjusted based on the time it takes to get all these statistics. In addition, each sample records the time it takes to measure by the actual elapsed time between each sample. This can be used to calculate the delay of the cpustat itself.
When running without any parameters, cpustat displays the following information by default: sample interval: 200ms; summary interval: 2s (10 samples); display the first 10 processes; user filter: all;pid filter: all. As shown in the screenshot below:
$sudo $GOBIN/cpustat10 minutes to learn cpustat commands 10 minutes to learn cpustat commands
Cpustat-monitors Linux CPU usage
In the above output, the system-wide metric field shown earlier has the following meaning:
Usr-the min/avg/max value of user mode elapsed time as a percentage of CPU. Sys-the min/avg/max value of system mode elapsed time as a percentage of CPU. Nice-the min/avg/max value of user mode low priority elapsed time as a percentage of CPU. Idle-the min/avg/max value of user mode idle time as a percentage of CPU. Iowait-min/avg/max delay time waiting for disk IO. Prun-the number of min/avg/max processes that are runnable (same as average load). Pblock-the number of min/avg/max processes blocked by disk IO. Pstat-the number of processes / threads started during this summary interval.
The same as the output above, for a process, different columns mean:
Name-the process name obtained from / proc/pid/stat or / proc/pid/cmdline. Pid-process ID, also used as "tgid" (thread group ID). Min-the minimum sample of the user mode + system mode time of the pid, taken from / proc/pid/stat. The ratio is a percentage of CPU. Max-the largest sample of the user mode + system mode time of the pid, taken from / proc/pid/stat. Usr-the average user mode elapsed time of the pid during the summary period, taken from / proc/pid/stat. Sys-the average system mode elapsed time for this pid during the summary period, taken from / proc/pid/stat. Nice-represents the current "nice" value of the process, taken from / proc/pid/stat. A higher value means better (nicer). Runq-the amount of time that a process and all its threads can run but wait to run, taken from taskstats via netlink. The ratio is a percentage of CPU. Iow-the time that the process and all its threads are blocked by disk IO, taken from taskstats via netlink. The ratio is a percentage of CPU, averaging over the entire summary interval. Swap-the time that the process and all its threads wait to be swap in, taken from taskstats via netlink. Scale is the percentage of CPU, averaging over the entire summary interval. Vcx and icx-the total number of automatic context switches by the process and all its threads during the summary interval, taken from taskstats through netlink. Rss-the current RSS value obtained from / proc/pid/stat. It refers to the amount of memory that the process is using. Ctime-the sum of user mode + system mode CPU time waiting for the child process to exit during the summary interval, taken from / proc/pid/stat. Note that long-running child processes may confuse this value because the time is reported only after the child process exits. However, this is very helpful for calculating high-frequency cron tasks and health checks where CPU time is often used by multiple child processes. Thrd-summarizes the number of threads at the end of the interval, taken from / proc/pid/stat. Sam-the number of samples of the process during this summary interval. Processes that have recently started or exited may appear to be smaller than the sample size of the summary interval.
The following command shows the first 10 root user processes running on the system:
$sudo $GOBIN/cpustat-u root10 minutes to learn cpustat commands 10 minutes to learn cpustat commands
Find the process that the root user is running
To display the output in a better-looking terminal mode, use the-t option like this:
$sudo $GOBIN/cpustat-u root-t 10 minutes to learn cpustat commands 10 minutes to learn cpustat commands
Processes that root users are running
To view the first x processes (default is 10), you can use the-n option, and the following command shows the first 20 processes running on the system:
$sudo $GOBIN/cpustat-n 20
You can also use the-cpuprofile option to write CPU information to a file as follows, and then use the cat command to view the file:
$sudo $GOBIN/cpustat-cpuprofile cpuprof.txt$ cat cpuprof.txt
To display help information, use the-h option as follows:
The above $sudo $GOBIN/cpustat-h is all the contents of this article entitled "how to install and use cpustat under Linux". Thank you for reading! Hope to share the content to help you, more related 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.