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配置mysql的教程(推荐)

Linux系统自带Python,且根据系统自带资源来对python配置mysql;安装需要已配置好正确的yum源; 在python未配置mysql的情形下,直接import MySQLd...

python base64库给用户名或密码加密的流程

给明文密码加密的流程: import base64 pwd_after_encrypt = base64.b64encode(b'this is a scret!') pwd_bef...

Python中生成一个指定长度的随机字符串实现示例

方法一: 定义一个函数,参数为所要生成随机字符串的长度。通过random.randint(a, b)方法得到随机数字,具体函数如下: def generate_random_str(...

详解python-图像处理(映射变换)

详解python-图像处理(映射变换)

做计算机视觉方向,除了流行的各种深度学习算法,很多时候也要会基础的图像处理方法。 记录下opencv的一些操作(图像映射变换),日后可以方便使用 先上一张效果图 图二和图三是同一种方法...

python 获取微信好友列表的方法(微信web)

如下所示: import urllib import urllib2 import os import time import re import cookielib im...