简体   繁体   English

检索CPU使用率百分比

[英]Retrieve CPU usage percentage

I want to retrieve percentage processor usage but no other commands that show tons of numbers. 我想检索处理器使用率百分比,但没有其他显示大量数字的命令。 There's a solution using 'grep' or 'awk' or something like that. 有一个使用“ grep”或“ awk”之类的解决方案。

~$ vmstat
procs -----------memory---------- ---swap-- -----io---- -system-- ----cpu----
 r  b   swpd   free   buff  cache   si   so    bi    bo   in   cs us sy id wa
 0  0 1447984 190232 146508 4983236  0    0     0    10    0    0  2  1 97  0

I used the vmstat command, and I only want the 'sy' number in the cpu colon. 我使用了vmstat命令,并且我只想要CPU冒号中的'sy'号。

top command output :
    [m20176 libvirt-  20   0 4368m 4,0g 3028 S  12,0 25,3  24695:44 kvm               (B[m[39;49m

(B[m25320 libvirt-  20   0 3520m 3,0g 3056 S   2,7 19,2  21786:15 kvm               (B[m[39;49m

(B[m    1 root      20   0 10656  624  596 S   0,0  0,0   5:46.26 init              (B[m[39;49m
(B[m    2 root      20   0     0    0    0 S   0,0  0,0   0:00.12 kthreadd          (B[m[39;49m
(B[m    3 root      20   0     0    0    0 S   0,0  0,0 476:10.20 ksoftirqd/0       (B[m[39;49m
(B[m    6 root      rt   0     0    0    0 S   0,0  0,0   0:08.16 migration/0       (B[m[39;49m
(B[m    7 root      rt   0     0    0    0 S   0,0  0,0   2:03.06 watchdog/0        (B[m[39;49m
(B[m    8 root      rt   0     0    0    0 S   0,0  0,0   0:04.30 migration/1       (B[m[39;49m
(B[m   10 root      20   0     0    0    0 S   0,0  0,0   0:38.83 ksoftirqd/1       (B[m[39;49m
(B[m   12 root      rt   0     0    0    0 S   0,0  0,0   1:43.93 watchdog/1        (B[m[39;49m
(B[m   13 root      rt   0     0    0    0 S   0,0  0,0   0:03.41 migration/2       (B[m[39;49m
(B[m   15 root      20   0     0    0    0 S   0,0  0,0   2:42.22 ksoftirqd/2       (B[m[39;49m
(B[m   16 root      rt   0     0    0    0 S   0,0  0,0   1:49.23 watchdog/2        (B[m[39;49m
(B[m   17 root      rt   0     0    0    0 S   0,0  0,0   0:04.42 migration/3       (B[m[39;49m
(B[m   19 root      20   0     0    0    0 S   0,0  0,0 408:06.08 ksoftirqd/3       (B[m[39;49m

Here, process uses per process are displayed (only a part). 在此,显示每个过程的过程用途(仅一部分)。 I found this command : 我发现了这个命令:

`top -b -d1 -n1|grep -i "Cpu(s)"|head -c21|cut -d ' ' -f3|cut -d '%' -f1`

here . 在这里 But this is CPU usage from startup, not real-time usage. 但这是启动时的CPU使用率,而不是实时使用率。

A simple awk could help you here(considering that you want to print only the numbers of sy column). 一个简单的awk可以在这里为您提供帮助(考虑到您只想打印sy列的数字)。

vmstat 1 10 | awk 'FNR>1{print $(NF-3)}'

NOTE: I have used vmstat 1 10 to perform 10 times vmstat command on server and then I am printing the $(NF-3) value which is 4th value from last. 注意:我使用vmstat 1 10在服务器上执行10次vmstat命令,然后打印$(NF-3)值,该值是最后一个值的第4个值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 计算进程的cpu使用率占内核空间的百分比 - calculate cpu usage of a process as percentage in kernel space 准确计算 Linux 中以百分比给出的 CPU 使用率? - Accurate calculation of CPU usage given in percentage in Linux? 如何以百分比百分比获取 C 程序中的 CPU 使用率 - How to get CPU usage in C program with percentage % linux/ubuntu 中的总体 CPU 使用率和内存(RAM)使用率百分比 - overall CPU usage and Memory(RAM) usage in percentage in linux/ubuntu 不使用top命令以百分比显示CPU核心使用情况 - Display CPU cores usage in percentage without using top command 在 Linux 上检索单个进程的 CPU 使用率和内存使用率? - Retrieve CPU usage and memory usage of a single process on Linux? 为什么我看到一个进程的 CPU 使用率很高,但总体 CPU 空闲百分比很高? - Why do I see high CPU usage for one process but the overall CPU idle percentage is high? 最高命令:进程中的CPU%如何高于总体CPU使用率百分比 - Top Command: How come CPU% in process is higher than in overall CPU Usage Percentage 获取单个进程的平均 CPU 使用百分比,直到我在 bash 脚本中将其杀死 - Get average CPU Usage percentage of single process until I kill it in bash script 最大CPU使用率(允许的最大CPU使用率) - Max CPU usage (max allowed CPU usage)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM