在Linux计算机上绘制每用户CPU使用情况的图表

我希望图形化(图形输出很棒,即.png文件)以下情况:我有用户A,B和C.我限制他们的资源,以便当所有用户同时运行CPU密集型任务时,这些进程将使用25%,25%和50%的CPU.我知道我可以使用top来获取实时统计数据,但不知道如何处理它们.我已经搜索了巨大的顶级手册页,但没有找到关于输出可以绘制的数据的主题.理想情况下,图表显示的跨度可能为30秒.任何想法如何实现这一目标?

解决方法

I know I can get the real-time stats using top but have no idea what
to do with them

批处理模式可能很有用:

-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="a b c"

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

这是结果:

dawei

【声明】:唐山站长网内容转载自互联网,其相关言论仅代表作者个人观点绝非权威,不代表本站立场。如您发现内容存在版权问题,请提交相关链接至邮箱:bqsm@foxmail.com,我们将及时予以处理。