我是靠谱客的博主 内向黑裤,这篇文章主要介绍写了个监控nginx进程的Python脚本,现在分享给大家,希望可以做个参考。

复制代码 代码如下:

#!/usr/bin/env python
import os, sys, time

while True:
time.sleep(3)
try:
ret = os.popen('ps -C nginx -o pid,cmd').readlines()
if len(ret) < 2:
print "nginx process killed, restarting service in 3 seconds."
time.sleep(3)
os.system("service nginx restart")
except:
print "Error", sys.exc_info()[1]

设置文件可执行属性,加入到/etc/rc.local,总算放心了。
这种方法还可以监控别的进程,我相信应该有现成的监控软件,但是我觉得写个脚本更方便。

最后

以上就是内向黑裤最近收集整理的关于写了个监控nginx进程的Python脚本的全部内容,更多相关写了个监控nginx进程内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(184)

评论列表共有 0 条评论

立即
投稿
返回
顶部