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获取屏幕截图的4种方法详解

Python获取电脑截图有多种方式,具体如下: PIL中的ImageGrab模块 windows API PyQt pyautogui PIL中的ImageGrab模块 impor...

Python实现简单过滤文本段的方法

本文实例讲述了Python实现简单过滤文本段的方法。分享给大家供大家参考,具体如下: 一、问题: 如下文本: ## Alignment 0: score=397.0 e_value=...

python实现推箱子游戏

python实现推箱子游戏

本文实例为大家分享了python实现推箱子游戏的具体代码,供大家参考,具体内容如下 题目描述: 最短路径为: uurrDDDDuuuulldRurDDDrddLLrruLuuulldR...

对python中的float除法和整除法的实例详解

从python2.2开始,便有两种除法运算符:"/"、"//"。两者最大区别在: python2.2前的版本和python2.2以后3.0以前的版本的默认情况下,"/"所做的除法是以一种...

pyqt4教程之messagebox使用示例分享

复制代码 代码如下:#coding=utf-8#对话框import sysfrom PyQt4 import QtGui, QtCoreclass Window( QtGui.QWidg...