开发者

Efficiently monitoring httpd children and signalling those using too much memory/cpu

开发者 https://www.devze.com 2023-03-30 13:58 出处:网络
We use Apache/mod_perl 2 and occasionally get a child httpd process that spins out of control, either consuming ever-increasing amounts of memory or max cpu.

We use Apache/mod_perl 2 and occasionally get a child httpd process that spins out of control, either consuming ever-increasing amounts of memory or max cpu.

I would like to monitor for such children every second or so, and when finding one, send it a USR2 signal so it can dump its current Perl stack to our error logs.

(Note that we are using rlimit/BSD::Resource, but when a process exceeds its memory rlimit, it dies immediately with no good way to log or take action (see Getting stack trace from Perl "Out of memory" error). So AFAICT rlimit will have to be complemented by an external monitoring program.)

I see that monit is highly regarded, but I can't figure out any way to monitor and send a signal to an individual httpd process. It seems geared towards killing or restarting services like apache as a whole. Am I missing something?

If I have to write a Perl script that does this, is there anything that will efficiently monitor the process table? Proc::ProcessTable takes .02 secs of cpu to generate a single table, so running that开发者_JAVA技巧 every second seems unnecessarily expensive. Opening up a "/usr/bin/top -b -d 1 |" and parsing the results is my current best idea.

Obviously would rather not badly reinvent a wheel if possible.

Thanks!


You can use control groups to quickly get a list of processes associated with apache, and focus your attention there. Simply put the main apache process into a control group prior to it spawning any child processes (eg, you could have a launcher process add itself to a control group), then read off the tasks file in the cgroup virtual directory. For each PID there, examine its CPU usage via the normal /proc mechanisms.

0

精彩评论

暂无评论...
验证码 换一张
取 消