获得Apache的总的CPU使用率(Linux版) [英] get apache total cpu usage in (linux)
本文介绍了获得Apache的总的CPU使用率(Linux版)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想编写一个脚本(在Linux bash或Perl的),它监视Apache和重新启动的情况下,超过X%的CPU Apache的。
我明白我需要因为它开启子过程中得到的Apache的总的CPU使用率。
I want to write a script (in bash or Perl on linux) which monitors the Apache and restarts the Apache in case it exceeds X% CPU. I understand that I need to get the total CPU usage of Apache since it opens child process.
我怎样才能获得Apache的总的CPU使用率?
How can I get the total CPU usage of Apache?
推荐答案
请尝试以下方法,但一定要用你的实际单(我的是更新Apache的进程名的httpd
)
Try the following, but make sure to update the Apache-process name with your actual one (mine is httpd
):
ps u -C httpd | awk '{sum += $3} END {print sum}'
这将得到所有Apache进程列表,运行和总结 PS
的输出%CPU
列使用 AWK
。
This will get a list of all apache processes running and sum the %CPU
column of ps
's output using awk
.
这篇关于获得Apache的总的CPU使用率(Linux版)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文