有效监控 httpd 子进程并向那些使用过多内存/CPU 的进程发出信号

发布于 2024-12-01 01:08:30 字数 789 浏览 1 评论 0原文

我们使用 Apache/mod_perl 2,偶尔会出现一个失控的 httpd 子进程,要么消耗不断增加的内存量,要么消耗最大 cpu。

我想每隔一秒左右监视一次这样的孩子,当找到一个时,向它发送一个 USR2 信号,以便它可以将其当前的 Perl 堆栈转储到我们的错误日志中。

(请注意,我们使用的是 rlimit/BSD::Resource,但是当进程超过其内存 rlimit 时,它会立即终止,并且没有好的方法来记录或采取操作(请参阅 从 Perl 获取堆栈跟踪“内存不足”错误)。因此 AFAICT rlimit 必须由外部监控程序来补充。)

我看到 monit 受到高度重视,但我无法找出任何方法来监视并向单个 httpd 进程发送信号。它似乎旨在杀死或重新启动整个 apache 等服务。我错过了什么吗?

如果我必须编写一个 Perl 脚本来执行此操作,有什么可以有效地监视进程表吗? Proc::ProcessTable 需要 0.02 秒的 cpu 来生成一个表,因此每次运行该表第二似乎不必要地昂贵。打开“/usr/bin/top -b -d 1 |”解析结果是我目前最好的想法。

如果可能的话,显然宁愿重新发明轮子。

谢谢!

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 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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

dawn曙光 2024-12-08 01:08:30

您可以使用控制组快速获取与apache相关的进程列表,并将你的注意力集中在那里。只需将主 apache 进程放入控制组中,然后再生成任何子进程(例如,您可以将启动器进程添加到控制组中),然后读取 cgroup 虚拟目录中的任务文件。对于其中的每个 PID,通过正常的 /proc 机制检查其 CPU 使用情况。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文