python检测lvs real server状态

yipeiwu_com5年前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变量、数据类型、数据类型转换相关函数用法实例详解

本文实例讲述了Python变量、数据类型、数据类型转换相关函数用法。分享给大家供大家参考,具体如下: python变量的使用不需要进行类型声明(类型名 变量名),给一个变量名赋什么值就是...

Python Pillow Image Invert

本文主要是利用Python的第三方库Pillow,实现单通道灰度图像的颜色翻转功能。 # -*- encoding:utf-8 -*- import os import sys fr...

微信公众号token验证失败解决方案

我用的是python3+,而官网给的例子是python2的写法。问题就在python版本不同。 下面是截取官方的实例代码的一部分 list = [token, timestamp,...

Python获取某一天是星期几的方法示例

Python获取某一天是星期几的方法示例

本文实例讲述了Python获取某一天是星期几的方法。分享给大家供大家参考,具体如下: 这里以2017年的春节(1月28号)为例: import re; import time; im...

使用Python读取安卓手机的屏幕分辨率方法

直接代码吧: import os import sys import json import re def _get_screen_size(): '获取手机屏幕大小' size...