我想要绘制graphics(graphics输出会很好,即一个.png文件)下列情况:我有用户A,B和C.我限制其资源,以便所有用户同时运行一个CPU密集型任务时,这些进程将使用25%,25%和50%的CPU。 我知道我可以得到使用top的实时统计信息,但不知道如何处理它们。 我已经search了巨大的top man page,但是在输出可以绘制数据的主题上还没有find太多东西。 理想情况下,图表会显示30秒的跨度。 任何想法如何实现这一目标?
我知道我可以得到使用顶部的实时统计信息,但不知道如何处理它们
批处理模式可能是有用的:
-b : Batch mode operation Starts top in 'Batch mode', which could be useful for sending output from top to other programs or to a file. In this mode, top will not accept input and runs until the iterations limit you've set with the '-n' command-line option or until killed.
例如:
$ top -b -n 1 -u <user> | awk 'NR > 7 { sum += $9 } END { print sum }'
Ganglia Gmetric可以用来为此绘制图表。
cpu_per_user_gmetric.sh
#!/bin/bash USERS="abc" for user in $USERS; do /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 done
crontab -l
* * * * * /path/to/cpu_per_user_gmetric.sh
结果如下:

tload命令通过ASCII图表示平均系统负载的graphics表示。 该命令可用于在terminal上提供graphics。 该命令的语法是:
tload [options] [terminal]
如果未提供terminal作为此命令的参数,则默认情况下会输出当前terminal上的graphics。 所以这个命令最简单的forms是:
$ tload
也许你可以使用collectd和适应一个可用的插件 ? 是的,列出的内容都不会完全符合你的要求,但另一方面,它们很容易修改,我认为你可以从例子processes插件开始,并从那里开始工作。
尝试sar和sadf来收集和准备数据,以便于绘图。 http://sebastien.godard.pagesperso-orange.fr/documentation.html