mar*_*t1n 7 linux performance-monitoring graph cpu-usage
我想绘制以下情况(图形输出会很棒,即 .png 文件)以下情况:我有用户 A、B 和 C。我限制他们的资源,以便当所有用户同时运行 CPU 密集型任务时,这些进程将使用 25%、25% 和 50% 的 CPU。我知道我可以使用实时统计数据,top但不知道如何处理它们。我搜索了巨大的top手册页,但没有找到关于输出可绘制数据的太多内容。理想情况下,图表会显示大约 30 秒的跨度。任何想法如何实现这一目标?
小智 7
该tload命令通过 ASCII 图形表示平均系统负载的图形表示。此命令可用于在终端上提供图形。命令的语法是:
tload [options] [terminal]
Run Code Online (Sandbox Code Playgroud)
如果终端未作为此命令的参数提供,则默认情况下它会在当前终端上输出图形。所以这个命令的最简单形式是:
$ tload
Run Code Online (Sandbox Code Playgroud)
\n\n\n我知道我可以使用 top 获取实时统计数据,但不知道如何处理它们
\n
批处理模式可能很有用:
\n\n -b : Batch mode operation\n Starts top in \xe2\x80\x99Batch mode\xe2\x80\x99, which could be useful for sending output from top to other programs or\n to a file. In this mode, top will not accept input and runs until the iterations limit you\xe2\x80\x99ve set\n with the \xe2\x80\x99-n\xe2\x80\x99 command-line option or until killed.\nRun Code Online (Sandbox Code Playgroud)\n\n例如:
\n\n$ top -b -n 1 -u <user> | awk \'NR > 7 { sum += $9 } END { print sum }\'\nRun Code Online (Sandbox Code Playgroud)\n\nGanglia Gmetric可用于为此绘制图表。
\n\ncpu_per_user_gmetric.sh
#!/bin/bash\nUSERS="a b c"\n\nfor user in $USERS; do\n /usr/bin/gmetric --name CPU_per_"$user"_user --value `top -b -n 1 -u $user | awk \'NR>7 { sum += $9; } END { print sum; }\'` --type uint8 --unit Percent\ndone\nRun Code Online (Sandbox Code Playgroud)\n\ncrontab -l
* * * * * /path/to/cpu_per_user_gmetric.sh\nRun Code Online (Sandbox Code Playgroud)\n\n这是结果:
\n\n