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校验SQL脚本命名规则

详解python校验SQL脚本命名规则

需求背景 检查脚本文件中SQL语句是否按规范编写,规则如下: 创建表时,表名称需以"t_"开头且均为小写 增加和创建列时,列名称均为小写字母和_组成 创建函数,函数名称需以...

Python中的jquery PyQuery库使用小结

pyquery库是jQuery的Python实现,可以用于解析HTML网页内容,使用方法:复制代码 代码如下:from pyquery import PyQuery as pq1、可加载...

对python3 一组数值的归一化处理方法详解

1、什么是归一化: 归一化就是把一组数(大于1)化为以1为最大值,0为最小值,其余数据按百分比计算的方法。如:1,2,3.,那归一化后就是:0,0.5,1 2、归一化步骤: 如:2,4,...

python关闭windows进程的方法

本文实例讲述了python关闭windows进程的方法。分享给大家供大家参考。具体如下: 下面的python代码根据进程的名字调用windows的taskkill命令关闭指定的进程...

Python列表append和+的区别浅析

在python中使用列表的时候大家经常会需要向一个列表中添加一个元素,像下面这两种使用方法需要注意: 复制代码 代码如下: t = [1, 2, 3] t1 = t.append([4]...