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中使用selenium的示例

最近基于selenium写了一个python小工具,记录下学习记录,自己运行的环境是Ubuntu 14.04.4, Python 2.7,Chromium 49.0,ChromeDriv...

python 重定向获取真实url的方法

楼主在做公司项目的时候遇到url重定向的问题,因此上网简单查找,作出如下结果 由于使用的是语言是python所以以下是python的简单解决方案 http_headers = { '...

图文详解Django使用Pycharm连接MySQL数据库

图文详解Django使用Pycharm连接MySQL数据库

在 Pycharm 的右上方找到 Database 点击 依次点击,选择 MySQL 数据库 点击 Download 下载驱动文件 下载完成后对数据库的相关信息进行填写 填写完成...

Python 给屏幕打印信息加上颜色的实现方法

Python 给屏幕打印信息加上颜色的实现方法

语法 print('\033[显示方式;字体色;背景色m文本\033[0m') # 三种设置都可以忽略不写,都不写则为默认输出 配置如下 # 字体 背景 颜色 # ------...

Python查询IP地址归属完整代码

本文实例为大家分享了Python查询IP地址归属的具体代码,供大家参考,具体内容如下 #!/usr/bin/env python # -*- coding: utf-8 -*- #...