大网数据广告活动
服务器运维问答

Restart apache with monit

· 52CE 我爱测

I'm trying to figure out some issues on my server where my CPU is reaching 100% utilization every other day. This causes all my websites and http services to fail. How can I configure monit to restart the httpd service when my cp…

问题原文

原帖链接 · ibyte · CC BY-SA 4.0

I'm trying to figure out some issues on my server where my CPU is reaching 100% utilization every other day. This causes all my websites and http services to fail.

How can I configure monit to restart the httpd service when my cpu hits 100% for say 10 cycles?

I'm still new to linux and centos. Learning my way around it and I've tried to research this for a while, but I could not find a proper answer to this.

Thanks for looking

Update

Thanks for your response. When the CPUs are running at 100%, I've run the top command and I can see that user nobody is consuming all of it on httpd service. I have a few apps that use php scripts, but their error logs all seem fine.

I'm suspecting a particular wordpress theme is causing this error due to a loop while updating the website. This particular website also shows me a loopback test failed error while all other wordpress sites on the same server are running fine.

So, until I can find out the culprit, I simply want to restart the service httpd when CPU utilization reaches say 95% for 10 cycles.

I hope that is enough clarity for someone to kindly give me a solution.

已采纳解答

原帖链接 · Dre · CC BY-SA 4.0

How can I configure monit to restart the httpd service when my cpu hits 100% for say 10 cycles?

I would use this line in Monit to get what you are looking for:

if cpu > 100% for 10 cycles then restart

Altogether it could look something like this:

check process httpd with pidfile /path/to/your/pid
    group mail
    start program = "/etc/init.d/httpd start"
    stop program = "/etc/init.d/httpd stop"
    if cpu > 100% for 10 cycles then restart

Though this should do as you requested, I'm not sure this will give you the results you are looking for as Apache may have several processes running at any one time.

For your Wordpress woes, Wordpress Query Monitor might help you to track down the culprit.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2020-07-23)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。