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解析json之ValueError: Expecting property name enclosed in double quotes: line 1 column 2(char 1)

前言 在Python中提供了json包来方便快捷的解析json字串的转换过程,但是碰到了一个比较奇怪的问题,就是不太正确的json串如何来解析? 1. 问题的提出 今天在处理一个http...

Python内置函数——__import__ 的使用方法

Python内置函数——__import__ 的使用方法

__import__() 函数用于动态加载类和函数 。 如果一个模块经常变化就可以使用 __import__() 来动态载入。 语法 __import__ 语法: __import...

python创建学生管理系统

python创建学生管理系统

使用python创建学生管理系统,供大家参考,具体内容如下 创建学生管理系统,可谓是学习编程最基础的一小步。 主要是分为以下几个思路: 接下来直接上源码 #!/usr/bin/py...

PyTorch预训练的实现

前言 最近使用PyTorch感觉妙不可言,有种当初使用Keras的快感,而且速度还不慢。各种设计直接简洁,方便研究,比tensorflow的臃肿好多了。今天让我们来谈谈PyTorch的...

python机器人运动范围问题的解答

机器人的运动范围Python实现: 问题:地上有个 m 行 n 列的方格。一个机器人从坐标(0,0)的格子开始移动,它每一次可以向左、右、上、下移动一格,但不能进入行坐标和列坐标的数位之...