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定时检查启动某个exe程序适合检测exe是否挂了

详见代码如下: 复制代码 代码如下: import threading import time import os import subprocess def get_process_c...

在Python的Flask框架中使用模版的入门教程

 概述 如果你已经阅读过上一个章节,那么你应该已经完成了充分的准备工作并且创建了一个很简单的具有如下文件结构的Web应用:   microblog  &nb...

Python 调用 zabbix api的方法示例

前提准备: 1.使用python requests模块 2.了解json 3.zabbix api的具体调用建议先浏览一下官网 先上代码: import requests,json...

python实现求特征选择的信息增益

使用python语言,实现求特征选择的信息增益,可以同时满足特征中有连续型和二值离散型属性的情况。 师兄让我做一个特征选择的代码,我在网上找了一下,大部分都是用来求离散型属性的信息益益...

Python3将数据保存为txt文件的方法

Python3将数据保存为txt文件的方法

Python3将数据保存为txt文件的方法,具体内容如下所示: f = open("data/model_Weight.txt",'a') #若文件不存在,系统自动创建。'a'表...