没有合适的资源?快使用搜索试试~ 我知道了~
首页python监控进程状态,记录重启时间及进程号的实例
资源详情
资源评论
资源推荐
python监控进程状态监控进程状态,记录重启时间及进程号的实例记录重启时间及进程号的实例
今天小编就为大家分享一篇python监控进程状态,记录重启时间及进程号的实例,具有很好的参考价值,希望对
大家有所帮助。一起跟随小编过来看看吧
本脚本为本人在性能测试过程中编写,用于对进程状态的监控,也可以用于日常的监控,适用性一般,扩展性还行
# -*- coding: UTF-8 -*-
# author=baird_xiang
import os
import time
import re
import copy
nginxRestart_num= -1
nginxReload_num= -1
logSender_num= -1
es_num= -1
nginxParent_pid=[]
nginxChild_pid=[]
logSender_pid=[]
es_pid=[]
nginxRestart_time =[]
nginxReload_time=[]
logSender_time=[]
es_time=[]
def get_restart(thread_name):
global nginxRestart_num,nginxReload_num,logSender_num,es_num
while True:
try:
for i in thread_name:
if i=='nginx_restart':
nP_pid = os.popen("sudo pgrep -lo nginx |grep -v grep|awk '{print $1}'").read()
nP_time = os.popen("sudo ps aux|grep nginx |grep -v grep|awk 'NR==1{print $9}'").read()
nginx_path = os.popen("sudo ps aux|grep nginx |grep -v grep|awk 'NR==1{print $11}'").read()
date = time.strftime('%Y-%m-%d',time.localtime(time.time()))
nP_time_now = date + '-' + nP_time.split('')[0]
if nP_pid and (nP_pid not in nginxParent_pid) and (nginx_path=='/usr/sbin/nginx'):
nginxParent_pid.append(nP_pid)
nginxRestart_num=nginxRestart_num+1
# if nP_time and (nP_time_now not in nginxRestart_time) and (color!='-c'):
nginxRestart_time.append(nP_time_now)
elif i=='nginx_reload':
nR_pid = os.popen("sudo pgrep -ln nginx|grep -v grep |awk '{print $1}'").read()
nR_time = os.popen("sudo ps aux|grep nginx |grep -v grep|awk 'NR==2{print $9}'").read()
nginx_path = os.popen("sudo ps aux|grep nginx |grep -v grep|awk 'NR==1{print $11}'").read()
date = time.strftime('%Y-%m-%d',time.localtime(time.time()))
nR_time_now = date + '-' + nR_time.split('')[0]
if nR_pid and (nR_pid not in nginxChild_pid) and (nginx_path=='/usr/sbin/nginx') :
nginxChild_pid.append(nR_pid)
nginxReload_num=nginxReload_num+1-nginxRestart_num
#if nR_time and (nR_time_now not in nginxReload_time) and (color!='-c'):
nginxReload_time.append(nR_time_now)
elif i=='log_sender':
lS_pid = os.popen("sudo ps aux|grep log_sender |grep -v grep|awk 'NR==1{print $2}'").read()
lS_time = os.popen("sudo ps aux|grep log_sender |grep -v grep|awk 'NR==1{print $9}'").read()
color = os.popen("sudo ps aux|grep log_sender |grep -v grep|awk 'NR==1{print $12}'").read()
wwwdate = os.popen("sudo ps aux|grep log_sender |grep -v grep|awk 'NR==1{print $1}'").read()
date = time.strftime('%Y-%m-%d',time.localtime(time.time()))
lS_time_now = date + '-' + lS_time.split('')[0]
if lS_pid and (color!='-c') and ( lS_pid not in logSender_pid ) and (wwwdate=='www-data\n'):
logSender_pid.append(lS_pid)
logSender_num=logSender_num+1
#if lS_time and (lS_time_now not in logSender_time) and (color!='-c'):
logSender_time.append(lS_time_now)
elif (i=='elasticsearch') and (os.popen("sudo ps -ef |grep elasticsearch |grep -v grep|awk 'NR==1{print $2}'").read()):
time.sleep(1)
e_pid = os.popen("sudo ps aux|grep elasticsearch |grep -v grep|awk 'NR==1{print $2}'").read()
e_time = os.popen("sudo ps aux|grep elasticsearch |grep -v grep|awk 'NR==1{print $9}'").read()
color = os.popen("sudo ps aux|grep elasticsearch |grep -v grep|awk 'NR==1{print $12}'").read()
elastic = os.popen("sudo ps aux|grep elasticsearch |grep -v grep|awk 'NR==1{print $1}'").read()
date = time.strftime('%Y-%m-%d',time.localtime(time.time()))
e_time_now = date + '-' + e_time.split('')[0]
if e_pid and (color!='-c') and (e_pid not in es_pid) and (elastic =='elastic+'):
es_pid.append(e_pid)
es_num=es_num+1
weixin_38632825
- 粉丝: 3
- 资源: 948
上传资源 快速赚钱
- 我的内容管理 收起
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
会员权益专享
最新资源
- zigbee-cluster-library-specification
- JSBSim Reference Manual
- c++校园超市商品信息管理系统课程设计说明书(含源代码) (2).pdf
- 建筑供配电系统相关课件.pptx
- 企业管理规章制度及管理模式.doc
- vb打开摄像头.doc
- 云计算-可信计算中认证协议改进方案.pdf
- [详细完整版]单片机编程4.ppt
- c语言常用算法.pdf
- c++经典程序代码大全.pdf
- 单片机数字时钟资料.doc
- 11项目管理前沿1.0.pptx
- 基于ssm的“魅力”繁峙宣传网站的设计与实现论文.doc
- 智慧交通综合解决方案.pptx
- 建筑防潮设计-PowerPointPresentati.pptx
- SPC统计过程控制程序.pptx
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论0