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创建一个文本文件,每行一个要下载的链接,然后打开迅雷,复制文本文件的内容,迅雷监测到剪切板变化,弹出下载全部链接的对话框~~ 实际情况是这样...

Python迭代和迭代器详解

迭代器 迭代器(iterator)有时又称游标(cursor)是程式设计的软件设计模式,可在容器物件(container,例如链表或阵列)上遍访的界面,设计人员无需关心容器物件的内存分配...

Python List列表对象内置方法实例详解

本文实例讲述了Python List列表对象内置方法。分享给大家供大家参考,具体如下: 前言 在上一篇中介绍了Python的序列和String类型的内置方法,本篇继续学习作为序列类型成员...

windows下安装Python虚拟环境virtualenvwrapper-win

1、安装 执行命令 pip install virtualenv 为了使用virtualenv更方便,可以借助 virtualenvwrapper 执行命令 pip install vi...

如何给Python代码进行加密

这篇文章主要介绍了如何给Python代码进行加密,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下 去年11月在PyCon China 2...