示例#1
0
def get_server_online(redis_connect):
    try:
        redis_cfg = server_util.str_to_redisconfig(redis_connect)
        logging.debug("host[%s], port[%s]" % (redis_cfg['host'], redis_cfg['port']))
        client = redis.Redis(host=redis_cfg['host'], port=redis_cfg['port'], socket_timeout=1)
        s = client.get("ldsg_local_system_status_key")
        if s:
            info = json.loads(s)
            online = info["connCount"]
            return online
    except:
        logging.debug(traceback.format_exc())
        pass
    return 0
示例#2
0
def get_server_online(redis_connect):
    try:
        redis_cfg = server_util.str_to_redisconfig(redis_connect)
        logging.debug("host[%s], port[%s]" %
                      (redis_cfg['host'], redis_cfg['port']))
        client = redis.Redis(host=redis_cfg['host'],
                             port=redis_cfg['port'],
                             socket_timeout=1)
        s = client.get("ldsg_local_system_status_key")
        if s:
            info = json.loads(s)
            online = info["connCount"]
            return online
    except:
        logging.debug(traceback.format_exc())
        pass
    return 0
示例#3
0
def get_online(server_id):
    servers = get_server_list(server_id)
    data = {}
    for server in servers:
        if not server:
            continue
        try:
            redis_cfg = str_to_redisconfig(server.redis_connect)
            client = redis.Redis(host=redis_cfg['host'], port=redis_cfg['port'])
            s = client.get("ldsg_local_system_status_key")
            if s:
                info = json.loads(s)
                online = info["connCount"]
                data[server.server_id] = online
        except:
            pass
        
    return data
示例#4
0
def get_online(server_id):
    servers = get_server_list(server_id)
    data = {}
    for server in servers:
        if not server:
            continue
        try:
            redis_cfg = str_to_redisconfig(server.redis_connect)
            client = redis.Redis(host=redis_cfg['host'],
                                 port=redis_cfg['port'])
            s = client.get("ldsg_local_system_status_key")
            if s:
                info = json.loads(s)
                online = info["connCount"]
                data[server.server_id] = online
        except:
            pass

    return data
示例#5
0
def main():
    """main"""
    servers = server_business.get_all_server_list()
    date = get_time()
    for server in servers:
        if not server:
            continue
        redis_cfg = str_to_redisconfig(server.redis_connect)
        logging.debug("host[%s], port[%s]" %
                      (redis_cfg['host'], redis_cfg['port']))
        client = redis.Redis(host=redis_cfg['host'], port=redis_cfg['port'])
        s = client.get("ldsg_local_system_status_key")
        if s:
            info = json.loads(s)
            online = info["connCount"]
            cursor = connection.cursor()
            try:
                cursor.execute(
                    "INSERT INTO stat_online(online, stat_time,server_id) VALUES(%d, '%s','%s')"
                    % (online, date, server.server_id))
            finally:
                connection.close()