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制作英文字典的具体代码,供大家参考,具体内容如下 功能有添加单词,多次添加单词的意思,查询,退出,建立单词文件。 keys=[] dic={} def...

Django中使用极验Geetest滑动验证码过程解析

Django中使用极验Geetest滑动验证码过程解析

一,环境部署 1.创建一个django测试项目 二,文档部署 1.下载安装python对应的SDK 使用命令从Github导入完整项目:git clone https://githu...

python实现最大优先队列

本文实例为大家分享了python实现最大优先队列的具体代码,供大家参考,具体内容如下 说明:为了增强可复用性,设计了两个类,Heap类和PriorityQ类,其中PriorityQ类继承...

Python zip()函数用法实例分析

本文实例讲述了Python zip()函数用法。分享给大家供大家参考,具体如下: 这里介绍python中zip()函数的使用: >>> help(zip) Help...

wxPython实现绘图小例子

wxPython实现绘图小例子

本文实例为大家分享了wxPython绘图小例子的具体实现代码,供大家参考,具体内容如下 一个绘图的例子: #!/usr/bin/env python # -*- coding: ut...