monitor site health with python

Use of python convenience class library, you can easily and quickly on site health monitoring, including on port 80 (ie, the site is running on port), the other tcp port monitor can understand the server about a health, use of librarymainly for urllib2 and the socket.

1、 monitor port 80 or any other sites running on port, such as tomcat, nginx, iis. Relatively simple to monitor this, directly through the urllib2 visit the Web site will be able to understand the situation of the site, if you do not return it will return false. As follows:

def http_monitor (server_info):
    try:
        data = urllib2.urlopen (server_info). read ()
        return True
    except:
        return False

2, monitor tcp port. This is trying to connect through the socket, and then determine whether the normal connectivity through try abnormal returns directly to false, connectivity to the Returns true if the connection is different newspaper.

the def tcp_monitor (port):
    try:
        the sock = the socket ()
        sock.connect (('localhost', int (port)))
        sock.close
        return True
    except:
        return False

本文固定链接: http://www.higis.org/en/2012/04/26/python-monitor-sitehealth/ | Hi,GIS


该日志由 H.J 于2012年04月26日发表在 WebServer, Program 分类下, 你可以发表评论,并在保留原文地址及作者的情况下引用到你的网站或博客。
原创文章转载请注明: monitor site health with python | Hi,GIS
关键字: ,

monitor site health with python:等您坐沙发呢!

发表评论

快捷键:Ctrl+Enter