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.
How can I get the total CPU usage of Apache?
Try the following, but make sure to update the Apache-process name with your actual one (mine is
httpd):This will get a list of all apache processes running and sum the
%CPUcolumn ofps‘s output usingawk.