python进程监控

2017-11-30  本文已影响45人  王哲理

#!/usr/bin/env python3

# -*- coding: utf-8 -*-

# Author:anthony

# date:20171129

# used:监控功能程序

import os

import Smail

import time

import smtplib

sender = '192.168.145.131@runoob.com'          # 邮件发送人

receivers = ['chris_apm@163.com']              # 邮件接收人

# 通知消息

message = """

service进程挂了,ip地址为192.168.145.131,赶紧看看。

microservice-web-api-user-0.0.1-SNAPSHOT_201711091536.jar

"""

# 检测进程是否存在

#servicename = raw_input('请输入进程全名称:')

process="/root/web_api.lock"

os.system("ps -ef|grep microservice-web-api-user-0.0.1-SNAPSHOT_201711091536.jar |grep -v grep >%s" % process)

# 报警邮件发送

if (os.path.getsize(process)):

            #os.system("nohup /root/servicename  &")

            try:

                        smtpObj = smtplib.SMTP('localhost')

                        smtpObj.sendmail(sender, receivers, message)

                        print ("Successfully sent email")

              except    smtplib.SMTPException:

                            print("Error: unable to send email")

上一篇下一篇

猜你喜欢

热点阅读