nickkkkkkk

  博客园 :: 首页 :: 新随笔 :: 联系 :: 订阅 :: 管理 ::
#!/usr/bin/env python

import getopt
import time
import sys, glob
from healthy import HealthyService
from healthy.ttypes import *


from thrift import Thrift
from thrift.transport import TSocket
from thrift.transport import TTransport
from thrift.protocol import TBinaryProtocol

def checkHealth(ip, port):
    try:
        transport = TSocket.TSocket(ip, port)
        transport.setTimeout(2000)
        transport = TTransport.TBufferedTransport(transport)
        protocol = TBinaryProtocol.TBinaryProtocol(transport)
        client = HealthyService.Client(protocol)
        transport.open()
        ret = client.healthy();
        transport.close()
        if ret == 0:
            date = time.strftime('%Y-%m-%d %H:%M:%S')
            print "\ntime  =>  "  + str(date)  + "\nERROR  =>  " + "check health failed" + "\n" + "ip  => " + ip  + "\n" + "port => " + str(port)
            return False
    except Exception, e:
        date = time.strftime('%Y-%m-%d %H:%M:%S')
        print "\ntime  =>  "  + str(date)  + "\nERROR  =>  " + str(e) + "\n" + "ip  => " + ip  + "\n" + "port => " + str(port)
        return False
    return True

if __name__ == "__main__":
    ip = sys.argv[1]
    port = sys.argv[2]
    for i in range(20):
        if checkHealth(ip, int(port)) == True:
            sys.exit(0)
        time.sleep(5)
    sys.exit(1)

 

posted on 2019-06-26 10:47  nickkkkkkk  阅读(125)  评论(0)    收藏  举报