从linux机器获取特定的mem和cpu值

时间:2017-06-26 09:13:55

标签: linux process

我有这个脚本:

echo $(date +%F-%H%M ) $( top -n 1 -b -c -p $ZK_PID,$KAFKA_PID,$AGENT_PID,$ENGINE_PID | tail -n 1) >> `hostname`_top.log

产生以下输出:

top - 06:32:15 up 7 days, 21:22,  2 users,  load average: 1.71, 1.66, 1.66
Tasks:   3 total,   0 running,   3 sleeping,   0 stopped,   0 zombie
%Cpu(s): 22.8 us, 15.9 sy,  0.0 ni, 61.1 id,  0.1 wa,  0.0 hi,  0.1 si,  0.0 st
KiB Mem : 14360876 total,   191296 free, 10837496 used,  3332084 buff/cache
KiB Swap:        0 total,        0 free,        0 used.  3066536 avail Mem

   PID USER      PR  NI    VIRT    RES    SHR S  %CPU %MEM     TIME+ COMMAND
 48721 equalum   20   0 12.828g 1.214g   6756 S   3.0  8.9   2176:15 /usr/lib/+
 52019 equalum   20   0 5809096 1.436g   5392 S   1.3 10.5 450:51.78 java -Dna+
 48411 equalum   20   0 4150868 403536   4992 S   0.0  2.8   3:56.87 /usr/lib/+

我试图获得这些进程的%CPU和%MEM值,我该怎么做?

1 个答案:

答案 0 :(得分:1)

尝试在脚本代码

之后添加此内容
| grep '%CPU|%MEM'