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实现七段数码管和倒计时效果

python实现七段数码管和倒计时效果

8是典型的七段数码管的例子,因为刚好七段都有经过,这里我写的代码是从1开始右转。 这是看Mooc视频写的一个关于用七段数码管显示当前时间 # -*-coding:utf-8 -*-...

Python with的用法

在Python中,with关键字是一个替你管理实现上下文协议对象的好东西。例如:file等。示例如下:    from __future__ import wi...

python 检查是否为中文字符串的方法

python 检查是否为中文字符串的方法

【目标需求】 查看某一个字符串是否为中文字符串 【解决办法】 def check_contain_chinese(check_str): for ch in check_str:...

django实现类似触发器的功能

django实现类似触发器的功能

这篇博客给大家讲解在django中类似触发器的效果 这篇教程分别会讲解 插入记录后,删除记录前,删除记录后这三个部分 相关环境 python 3.6 django2.0 我们一起来看看需...

python3.7 的新特性详解

python3.7 的新特性详解

Python 3.7增添了众多新的类,可用于数据处理、针对脚本编译和垃圾收集的优化以及更快的异步I/O。 Python这种语言旨在使复杂任务变得简单,最新版本Python 3.7已正式进...