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)

相关文章

在Django中限制已登录用户的访问的方法

有很多原因需要控制用户访问站点的某部分。 一个简单原始的限制方法是检查 request.user.is_authenticated() ,然后重定向到登陆页面: from djang...

Python实现生成随机日期字符串的方法示例

本文实例讲述了Python实现生成随机日期字符串的方法。分享给大家供大家参考,具体如下: 生成随机的日期字符串,用于插入数据库。 通过时间元组设定一个时间段,开始和结尾时间转换成时间戳。...

Python语言实现获取主机名根据端口杀死进程

推荐阅读:使用python检测主机存活端口及检查存活主机 下面给大家分享使用python语言实现获取主机名根据端口杀死进程代码。 ip=os.popen("ifconfig eth0...

在Django的URLconf中使用多个视图前缀的方法

在实践中,如果你使用字符串技术,特别是当你的 URLconf 中没有一个公共前缀时,你最终可能混合视图。 然而,你仍然可以利用视图前缀的简便方式来减少重复。 只要增加多个 pattern...

django如何通过类视图使用装饰器

需求:当我们想禁止ip黑名单访问我们的某些页面时,例如注册页面。应该怎么操作呢? 解决方案:这时候我们可以设计一个装饰器,过滤ip黑名单。 装饰器的写法如下: from functo...