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实现类似jQuery使用中的链式调用的示例

关于jQuery的链式调用 真正有意义的链式调用也就是方法链(method chaining)。方法链这个词是有的,而且使用的很广泛。其实很多人口中的“链式调用”实际上就是指方法链。但是...

一个小示例告诉你Python语言的优雅之处

比如, 我们希望希望检测"一段string是否以特定的字符串结尾?", 通常我们使用: if needle.endswith('ly') or needle.endswi...

把大数据数字口语化(python与js)两种实现

python 复制代码 代码如下:def fn(num):    '''    把数字口语化   ...

使用Python 正则匹配两个特定字符之间的字符方法

如下所示: # -*- coding: cp936 -*- import re   string = ...

Python中类型检查的详细介绍

Python中类型检查的详细介绍

前言 大家都知道Python 是一门强类型、动态类型检查的语言。所谓动态类型,是指在定义变量时,我们无需指定变量的类型,Python 解释器会在运行时自动检查。 与静态类型语言(如 C...