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)

相关文章

python3实现暴力穷举博客园密码

我之前想写路由器的密码暴力破解器,我手上只有极路由,发现极路由有安全限制,只能允许连续10密码错误,所以我改拿博客园练手。 博客园的博客有个功能是给博文设置一个密码,输入正确的密码才能看...

python 字典有序并写入json文件过程解析

python 字典有序并写入json文件过程解析

大致流程: 导包---import collections 新建一个有序字典---collections.OrderedDict() 写入json文件 代码: imp...

python 通过可变参数计算n个数的乘积方法

python 通过可变参数计算n个数的乘积方法

通过可变参数计算n个数的乘积: 代码如下: list = [] def the_input(count=eval(input("输入乘数的总个数:"))): for i in...

Python实现的特征提取操作示例

本文实例讲述了Python实现的特征提取操作。分享给大家供大家参考,具体如下: # -*- coding: utf-8 -*- """ Created on Mon Aug 21 1...

在python中安装basemap的教程

在python中安装basemap的教程

1. 确保python环境安装完毕且已配置好环境变量 2. 安装geos: pip install geos 3. 下载.whl文件: (1)pyproj‑1.9.5.1&...