python检测lvs real server状态

yipeiwu_com6年前Python基础

复制代码 代码如下:

import httplib
import os
import time

def check_http(i):
    try:
        conn=httplib.HTTPConnection(i, 80, timeout=2)
        conn.request("GET","/")
        response = conn.getresponse()
    except Exception as e:
        print "server "+i+" is down"
        print e
        print ""
        os.system('./delete_real_server.sh '+i)
    else:
        #print response.read()
        print "server "+i+" is up\n"
        os.system('./add_real.server.sh '+i)
       


if __name__=="__main__":
    httpservers=["127.0.0.1","10.0.0.1","192.168.35.28"]
    while 1:
        current_time=time.strftime('%Y-%m-%d %H:%M:%S',time.localtime(time.time()))
        for i in httpservers:
            check_http(i)
        print current_time+" check finish\n"
        time.sleep(60)

相关文章

Python比较两个图片相似度的方法

本文实例讲述了Python比较两个图片相似度的方法。分享给大家供大家参考。具体分析如下: 这段代码实用pil模块比较两个图片的相似度,根据实际实用,代码虽短但效果不错,还是非常靠谱的,前...

Python部署web开发程序的几种方法

1、fastcgi ,通过flup模块来支持,在nginx里对应的配置指令是 fastcgi_pass 2、http,nginx使用proxy_pass转发,这个要求后端appplica...

Python hmac模块使用实例解析

这篇文章主要介绍了Python hmac模块使用实例解析,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下 hmac模块的作用: 用于验证...

Python使用urllib2模块实现断点续传下载的方法

本文实例讲述了Python使用urllib2模块实现断点续传下载的方法。分享给大家供大家参考。具体分析如下: 在使用HTTP协议进行下载的时候只需要在头上设置一下Range的范围就可以进...

Python简单调用MySQL存储过程并获得返回值的方法

本文实例讲述了Python调用MySQL存储过程并获得返回值的方法。分享给大家供大家参考。具体实现方法如下: try: conn = MySQLdb.connect (...