“监控php进程的python脚本”的版本间的差异

来自linux中国网wiki
跳到导航 跳到搜索
docker>Evan
 
(导入1个版本)
 
(没有差异)

2019年10月14日 (一) 13:55的最新版本

#!/usr/bin/env python
#conding:utf8
# */3 * * * * /usr/bin/python  youpy.py
import urllib2
import os
import urllib
import time
import logging

import  socket
import fcntl
import struct

def logs(message):
  logspath = '/data/logs/php/'
  if os.path.exists(logspath) is False:
    os.makedirs(logspath)
  logging.basicConfig(level=logging.DEBUG,
    format='%(asctime)s %(filename)s[line:%(lineno)d] %(levelname)s %(message)s',
    datefmt='%a, %d %b %Y %H:%M:%S',
    filename=logspath+'checkphp-fpm.log',
    filemode='a')
  return logging.info(message)




def gethttpcode(url):
  status = urllib.urlopen(url).code
  return status



if __name__ == '__main__':
    httpcode = gethttpcode('http://127.0.0.1/check.php')
    if httpcode == 502:
        #os.system("/etc/init.d/php-fpm restart >/dev/null")
        message= " 502  Restart php-fpm right now "
        logs(message)
    elif httpcode == 200:
        message= "200 is ok now "
        logs(message)

see also

Python3:urllib中urlopen()函数新特点