Ejemplo n.º 1
0
 def _count_haproxy_processes(self, lb_list):
     num = 0
     for lb_id in lb_list:
         if util.is_lb_running(lb_id):
             # optional check if it's still running
             num += 1
     return num
Ejemplo n.º 2
0
def build_stats_message():
    # Example version 2 message without UDP:
    # {
    #   "id": "<amphora_id>",
    #   "seq": 67,
    #   "listeners": {
    #     "<listener_id>": {
    #       "status": "OPEN",
    #       "stats": {
    #         "tx": 0,
    #         "rx": 0,
    #         "conns": 0,
    #         "totconns": 0,
    #         "ereq": 0
    #       }
    #     }
    #  },
    #  "pools": {
    #    "<pool_id>:<listener_id>": {
    #      "status": "UP",
    #      "members": {
    #        "<member_id>": "no check"
    #      }
    #    }
    #  },
    #  "ver": 2
    # }
    global SEQ
    msg = {
        'id': CONF.amphora_agent.amphora_id,
        'seq': SEQ,
        'listeners': {},
        'pools': {},
        'ver': MSG_VER
    }
    SEQ += 1
    stat_sock_files = list_sock_stat_files()
    # TODO(rm_work) There should only be one of these in the new config system
    for lb_id, stat_sock_file in stat_sock_files.items():
        if util.is_lb_running(lb_id):
            (stats, pool_status) = get_stats(stat_sock_file)
            for row in stats:
                if row['svname'] == 'FRONTEND':
                    listener_id = row['pxname']
                    msg['listeners'][listener_id] = {
                        'status': row['status'],
                        'stats': {
                            'tx': int(row['bout']),
                            'rx': int(row['bin']),
                            'conns': int(row['scur']),
                            'totconns': int(row['stot']),
                            'ereq': int(row['ereq'])
                        }
                    }
            for pool_id, pool in pool_status.items():
                msg['pools'][pool_id] = {
                    "status": pool['status'],
                    "members": pool['members']
                }

    # UDP listener part
    udp_listener_ids = util.get_udp_listeners()
    if udp_listener_ids:
        listeners_stats = keepalivedlvs_query.get_udp_listeners_stats()
        if listeners_stats:
            for listener_id, listener_stats in listeners_stats.items():
                pool_status = keepalivedlvs_query.get_udp_listener_pool_status(
                    listener_id)
                udp_listener_dict = dict()
                udp_listener_dict['status'] = listener_stats['status']
                udp_listener_dict['stats'] = {
                    'tx': listener_stats['stats']['bout'],
                    'rx': listener_stats['stats']['bin'],
                    'conns': listener_stats['stats']['scur'],
                    'totconns': listener_stats['stats']['stot'],
                    'ereq': listener_stats['stats']['ereq']
                }
                if pool_status:
                    pool_id = pool_status['lvs']['uuid']
                    msg['pools'][pool_id] = {
                        "status": pool_status['lvs']['status'],
                        "members": pool_status['lvs']['members']
                    }
                msg['listeners'][listener_id] = udp_listener_dict
    return msg
Ejemplo n.º 3
0
def build_stats_message():
    """Build a stats message based on retrieved listener statistics.

    Example version 3 message without UDP (note that values are deltas,
    not absolutes)::

        {"id": "<amphora_id>",
         "seq": 67,
         "listeners": {
           "<listener_id>": {
             "status": "OPEN",
             "stats": {
               "tx": 0,
               "rx": 0,
               "conns": 0,
               "totconns": 0,
               "ereq": 0
             }
           }
         },
         "pools": {
             "<pool_id>:<listener_id>": {
               "status": "UP",
               "members": {
                 "<member_id>": "no check"
               }
             }
         },
         "ver": 3
        }
    """
    global SEQ
    msg = {
        'id': CONF.amphora_agent.amphora_id,
        'seq': SEQ,
        'listeners': {},
        'pools': {},
        'ver': MSG_VER
    }
    SEQ += 1
    stat_sock_files = list_sock_stat_files()
    # TODO(rm_work) There should only be one of these in the new config system
    for lb_id, stat_sock_file in stat_sock_files.items():
        if util.is_lb_running(lb_id):
            (stats, pool_status) = get_stats(stat_sock_file)
            for row in stats:
                if row['svname'] == 'FRONTEND':
                    listener_id = row['pxname']
                    delta_values = calculate_stats_deltas(listener_id, row)
                    msg['listeners'][listener_id] = {
                        'status': row['status'],
                        'stats': {
                            'tx': delta_values['bout'],
                            'rx': delta_values['bin'],
                            'conns': int(row['scur']),
                            'totconns': delta_values['stot'],
                            'ereq': delta_values['ereq']
                        }
                    }
            for pool_id, pool in pool_status.items():
                msg['pools'][pool_id] = {
                    "status": pool['status'],
                    "members": pool['members']
                }

    # UDP listener part
    lvs_listener_ids = util.get_lvs_listeners()
    if lvs_listener_ids:
        listeners_stats = keepalivedlvs_query.get_lvs_listeners_stats()
        if listeners_stats:
            for listener_id, listener_stats in listeners_stats.items():
                delta_values = calculate_stats_deltas(listener_id,
                                                      listener_stats['stats'])
                pool_status = (keepalivedlvs_query.
                               get_lvs_listener_pool_status(listener_id))
                lvs_listener_dict = dict()
                lvs_listener_dict['status'] = listener_stats['status']
                lvs_listener_dict['stats'] = {
                    'tx': delta_values['bout'],
                    'rx': delta_values['bin'],
                    'conns': listener_stats['stats']['scur'],
                    'totconns': delta_values['stot'],
                    'ereq': delta_values['ereq']
                }
                if pool_status:
                    pool_id = pool_status['lvs']['uuid']
                    msg['pools'][pool_id] = {
                        "status": pool_status['lvs']['status'],
                        "members": pool_status['lvs']['members']
                    }
                msg['listeners'][listener_id] = lvs_listener_dict
    persist_counters()
    return msg