Commit f4b549f7 authored by Waleed Akbar's avatar Waleed Akbar
Browse files

All KPI tags are added with metric.

parent d120ce74
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -86,7 +86,7 @@ class KpiValueComposer:
        sub_names = kpi_value = ""
        for line in lines:
            try:
                if pattern.search(line) and not line.startswith("# HELP") and not line.startswith("# TYPE"):
                if pattern.search(line) and not line.startswith("# HELP") and not line.startswith("# TYPE") and not 'device="lo"' in line:
                    (kpi_name, kpi_value) = line.split(" ")
                    if kpi_name.endswith('}'):
                        (kpi_name, sub_names) = kpi_name.replace('}','').split('{')
+13 −6
Original line number Diff line number Diff line
@@ -76,18 +76,25 @@ class KpiWriter:
    @staticmethod
    def write_metric_to_promtheus(event):
        event = ast.literal_eval(event)         # converted into dict
        print("New recevied event: {:}".format(event['kpi_description']))
        print("New recevied event: {:}".format(event))
        event_kpi_name = event['kpi_description']
        if event_kpi_name in KPIs_TO_SEARCH:
            PROM_METRICS[event_kpi_name].labels(
                    tag1 = "test tag value",
                    tag2 = "test tag value"
            ).set(event['kpi_value'])
                kpi_id          = event['kpi_id'],
                kpi_sample_type = event['kpi_sample_type'],
                device_id       = event['device_id'],
                endpoint_id     = event['endpoint_id'],
                service_id      = event['service_id'],
                slice_id        = event['slice_id'],
                connection_id   = event['connection_id'],
                link_id         = event['link_id']
            ).set(float(event['kpi_value']))
        time.sleep(0.05)

    @staticmethod
    def create_prom_metrics_name():
        metric_tags = ["tag1", "tag2"]
        metric_tags = ['kpi_id','kpi_sample_type','device_id',
                       'endpoint_id','service_id','slice_id','connection_id','link_id']
        for metric_key in KPIs_TO_SEARCH:
            metric_name        = metric_key
            metric_description = "description of " + str(metric_key)
@@ -95,7 +102,7 @@ class KpiWriter:
                PROM_METRICS[metric_key] = Gauge ( 
                    metric_name, metric_description, metric_tags, 
                    registry=KAFKA_REGISTERY )
                print("Metric pushed to Prometheus: {:}".format(PROM_METRICS[metric_key]))
                # print("Metric pushed to Prometheus: {:}".format(PROM_METRICS[metric_key]))
            except ValueError as e:
                if 'Duplicated timeseries' in str(e):
                    print("Metric {:} is already registered. Skipping.".format(metric_name))