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 smtplib模块自动收发邮件功能(二)

python smtplib模块自动收发邮件功能(二)

接上篇python smtplib模块自动收发邮件功能(一) ,用python smtplib模块实现了发送邮件程序了,那么接下来我们需要现在要解决的问题如何在 test_report\...

python邮件发送smtplib使用详解

本文实例为大家分享了python邮件发送smtplib使用具体代码,供大家参考,具体内容如下 文件形式的邮件 #!/usr/bin/env python3 #coding: utf...

Python入门篇之字典

字典由多个键及与其对应的值构成的对组成(把键值对成为项),每个键和它的值之间用冒号(:)隔开,项之间用逗号(,)隔开,而整个字典由一对大括号括起来。空字典由两个大括号组成:{} dict...

Python开发编码规范

这篇文档所给出的编码约定适用于在主要的Python发布版本中组成标准库的Python   代码,请查阅相关的关于在Python的C实现中C代码风格指南的描述...

跟老齐学Python之关于类的初步认识

在开始部分,请看官非常非常耐心地阅读下面几个枯燥的术语解释,本来这不符合本教程的风格,但是,请看官谅解,因为列位将来一定要阅读枯燥的东西的。这些枯燥的属于解释,均来自维基百科。 1、问题...