Ejemplo n.º 1
0
def format_applications(applications, broker_name, bip_codes):
    """Returns string with all metrics for all applications which ready to push to pushgateway."""
    metrics_annotation = get_metric_annotation()
    app_metric_data = str()
    for app in applications:
        app_list = app.split()
        bip_code = app_list[0].replace(':', '')
        if bip_code in bip_codes.keys():
            egname = app_list[bip_codes[bip_code][1]]
            app_name = app_list[bip_codes[bip_code][2]]
            status = app_list[bip_codes[bip_code][3]].replace(".", "")
            template_string = 'egname="{0}", brokername="{1}", appname="{2}"'.format(
                egname.replace("'", ""),
                broker_name,
                app_name.replace("'", ""))
            app_metric = '{0}{{{1}}} {2}\n'.format(
                get_metric_name(metric_label='status'),
                template_string,
                get_status(status=status))
            app_metric_data += app_metric
    if app_metric_data:
        app_metric_data = '{0}{1}'.format(
            metrics_annotation['status'],
            app_metric_data)
    return app_metric_data
Ejemplo n.º 2
0
def format_message_flows(message_flows, broker_name, bip_codes):
    """Returns string with all metrics for all message flows which ready to push to pushgateway."""
    metrics_annotation = get_metric_annotation()
    msg_flow_metric_data = str()
    for msg_flow in message_flows:
        msg_flow_list = msg_flow.split()
        bip_code = msg_flow_list[0].replace(':', '')
        if bip_code in bip_codes.keys():
            egname = msg_flow_list[bip_codes[bip_code][1]]
            app_name = msg_flow_list[bip_codes[bip_code][2]]
            message_flow_name = msg_flow_list[bip_codes[bip_code][3]]
            status = msg_flow_list[bip_codes[bip_code][4]].replace(".", "")
            template_string = 'egname="{0}", brokername="{1}", appname="{2}", messageflowname="{3}"'.format(
                egname.replace("'", ""),
                broker_name,
                app_name.replace("'", "").replace(",", ""),
                message_flow_name.replace("'", ""))
            msg_flow_metric = '{0}{{{1}}} {2}\n'.format(
                get_metric_name(metric_label='status'),
                template_string,
                get_status(status=status))
            msg_flow_metric_data += msg_flow_metric
    if msg_flow_metric_data:
        msg_flow_metric_data = '{0}{1}'.format(
            metrics_annotation['status'],
            msg_flow_metric_data)
    return msg_flow_metric_data
Ejemplo n.º 3
0
def format_broker(broker_name, status, qm_name):
    """Returns string with all metrics for broker which ready to push to pushgateway."""
    metrics_annotation = get_metric_annotation()
    template_string = 'brokername="{0}", qmname="{1}"'.format(
        broker_name, qm_name)
    broker_metric = '{0}{{{1}}} {2}\n'.format(
        get_metric_name(metric_label='status'), template_string,
        get_status(status=status))
    broker_metric = '{0}{1}'.format(metrics_annotation['status'],
                                    broker_metric)
    return broker_metric
Ejemplo n.º 4
0
def format_exec_groups(exec_groups, bip_codes):
    """Returns string with all metrics for all execution groups which ready to push to pushgateway."""
    metrics_annotation = get_metric_annotation()
    eg_metric_data = str()
    for eg in exec_groups:
        eg_list = eg.split()
        bip_code = eg_list[0].replace(':', '')
        if bip_code in bip_codes.keys():
            broker_name = eg_list[bip_codes[bip_code][1]]
            egname = eg_list[bip_codes[bip_code][2]]
            status = eg_list[bip_codes[bip_code][3]].replace(".", "")
            template_string = 'brokername="{0}", egname="{1}"'.format(
                broker_name.replace("'", ""), egname.replace("'", ""))
            eg_metric = '{0}{{{1}}} {2}\n'.format(
                get_metric_name(metric_label='status'), template_string,
                get_status(status=status))
            eg_metric_data += eg_metric
    if eg_metric_data:
        eg_metric_data = '{0}{1}'.format(metrics_annotation['status'],
                                         eg_metric_data)
    return eg_metric_data
Ejemplo n.º 5
0
 def test_get_status(self):
     """Test for `get_status` function."""
     self.assertEqual(0, get_status(status='stopped'))
     self.assertEqual(1, get_status(status='running'))