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实现控制台打印的方法

如下所示: #!/usr/bin/env python import os import sys class CConsole: M_MAP_COLOR = {\ 'COLO...

Python实现的Excel文件读写类

本文实例讲述了Python实现的Excel文件读写类。分享给大家供大家参考。具体如下: #coding=utf-8 #################################...

windows下Virtualenvwrapper安装教程

windows下Virtualenvwrapper安装教程

windows下安装Virtualenvwrapper 我们可以使用Virtualenvwrapper来方便地管理python虚拟环境,但是在windows上安装的时候.....直接 i...

python之pexpect实现自动交互的例子

Pexpect 是 Expect 语言的一个 Python 实现,是一个用来启动子程序,并使用正则表达式对程序输出做出特定响应,以此实现与其自动交互的 Python 模块。 Pexpec...

利用Pandas和Numpy按时间戳将数据以Groupby方式分组

首先说一下需求,我需要将数据以分钟为单位进行分组,然后每一分钟内的数据作为一行输出,因为不同时间的数据量不一样,所以所有数据按照最长的那组数据为准,不足的数据以各自的最后一个数据进行补足...