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中dict和set的用法讲解

Python中dict和set的用法讲解

dict Python内置了字典:dict的支持,dict全称dictionary,在其他语言中也称为map,使用键-值(key-value)存储,具有极快的查找速度。 举个例子,假设要...

Python按钮的响应事件详解

Python按钮的响应事件详解

import sys from PyQt5 import QtWidgets from PyQt5.QtWidgets import QMainWindow from test im...

一些Centos Python 生产环境的部署命令(推荐)

Just notes 拿到一台干净的centos之后, 初始化Python环境, 一些命令和问题记录而已 可以搞成脚本自动初始化, 当然, 用docker更好 基础环境 1. 创建用户...

python-django中的APPEND_SLASH实现方法

python-django中的APPEND_SLASH实现方法

关于django中的APPEND_SLASH APPEND_SLASH 它是啥? 看变量名大概能知道做什么,就是添加斜线,用路由系统那里。 路由文件,只写了路由关系代码 .........

python selenium 对浏览器标签页进行关闭和切换的方法

1.关闭浏览器全部标签页 driver.quit() 2.关闭当前标签页(从标签页A打开新的标签页B,关闭标签页A) driver.close() 3.关闭当前标签页(从标签...