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与文件进行交互的方法

本文介绍了用python与文件进行交互的方法,分享给大家,具体如下: 一.文件处理 1.介绍 计算机系统:计算机硬件,操作系统,应用程序 应用程序无法直接操作硬件,通过操作系统来操作文...

基于python全局设置id 自动化测试元素定位过程解析

背景: 在自动化化测试过程中,不方便准确获取页面的元素,或者在重构过程中方法修改造成元素层级改变,因此通过设置id准备定位。 一、python准备工作: 功能:用自动化的方式进行批量处理...

python 搭建简单的http server,可直接post文件的实例

server: #coding=utf-8 from BaseHTTPServer import BaseHTTPRequestHandler import cgi class Po...

python之消除前缀重命名的方法

● 脚本用途 遍历文件夹下的文件,消除文件名前的特征字符串。 ● 脚本实现 import os,sys import re from string import Template...

django 连接数据库 sqlite的例子

Aphorism the fight is worth it. django models 连接 sqlite 数据库 django 版本为 1.11.7 在 blog 项目下创建一个...