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)

相关文章

py-charm延长试用期限实例

不敢说得太明显太仔细,反正你懂的。 有两种方法,一种是搭建本地授权服务器,另一种是直接替换核心文件,修改对应的注册码。 先说第一种。 下载IntelliJIDEALicenseServ...

python pygame实现方向键控制小球

python pygame实现方向键控制小球

最后一个项目用到了pygame,  实现方向键控制小球,对于模块不熟悉的我还是查询了一些资料介绍。 import sys import pygame from pygame...

Python实现接受任意个数参数的函数方法

这个功能倒也不是我多么急需的功能,只是恰好看到了,觉得或许以后会用的到。功能就是实现函数能够接受不同数目的参数。 其实,在C语言中这个功能是熟悉的,虽说实现的形式不太一样。C语言中的ma...

python实现大转盘抽奖效果

python实现大转盘抽奖效果

本文实例为大家分享了python实现大转盘抽奖的具体代码,供大家参考,具体内容如下 选择转盘中的某一个方框,来进行抽奖 import tkinter #导入线程模块 import t...

Python对列表排序的方法实例分析

本文实例讲述了Python对列表排序的方法。分享给大家供大家参考。具体分析如下: 1、sort()函数 sort()函数使用固定的排序算法对列表排序。sort()函数对列表排序时改变了原...