美文网首页
python进程监控

python进程监控

作者: 王哲理 | 来源:发表于2017-11-30 17:59 被阅读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")

    相关文章

      网友评论

          本文标题:python进程监控

          本文链接:https://www.haomeiwen.com/subject/eytbbxtx.html