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中用Decorator来简化元编程的教程

少劳多得 Decorator 与 Python 之前引入的元编程抽象有着某些共同之处:即使没有这些技术,您也一样可以实现它们所提供的功能。正如 Michele Simionato 和我在...

Python 获得13位unix时间戳的方法

在python 开发web程序时,需要调用第三方的相关接口,在调用时,需要对请求进行签名。需要用到unix时间戳。 在python里,在网上介绍的很多方法,得到的时间戳是10位。而ja...

Python实现动态加载模块、类、函数的方法分析

本文实例讲述了Python实现动态加载模块、类、函数的方法。分享给大家供大家参考,具体如下: 动态加载模块: 方式1:系统函数__import__() 方式2:imp, import...

python简单文本处理的方法

本文实例讲述了python简单文本处理的方法。分享给大家供大家参考。具体如下: 由于有多线程的影响,c++项目打印出来的时间顺序不一致,导致不太好在excel中统计,故使用python写...

Python企业编码生成系统之主程序模块设计详解

本文实例讲述了Python企业编码生成系统之主程序模块。分享给大家供大家参考,具体如下: 一 点睛 主程序模块包括三部分: 1 主程序初始化 2 主程序界面 3 主程序逻辑 下面分别介绍...