From 9604945f57dbff85cf7948b475d6e86a0e5a2c90 Mon Sep 17 00:00:00 2001 From: Benjamin Diaz Date: Tue, 20 Nov 2018 11:56:43 -0300 Subject: [PATCH 1/1] Refactors Prometheus exporter to group metrics correctly by name Metric names were appearing duplicated in the exporter which generated issues integrating with external tools such as Metricbeat and Kibana. Signed-off-by: Benjamin Diaz --- Jenkinsfile | 2 +- osm_mon/collector/backends/prometheus.py | 19 ++++++++++--------- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 6afef69..635a5e6 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -5,7 +5,7 @@ properties([ string(defaultValue: env.GERRIT_REFSPEC, description: '', name: 'GERRIT_REFSPEC'), string(defaultValue: env.GERRIT_PATCHSET_REVISION, description: '', name: 'GERRIT_PATCHSET_REVISION'), string(defaultValue: 'https://osm.etsi.org/gerrit', description: '', name: 'PROJECT_URL_PREFIX'), - booleanParam(defaultValue: false, description: '', name: 'TEST_INSTALL'), + booleanParam(defaultValue: true, description: '', name: 'TEST_INSTALL'), string(defaultValue: 'artifactory-osm', description: '', name: 'ARTIFACTORY_SERVER'), ]) ]) diff --git a/osm_mon/collector/backends/prometheus.py b/osm_mon/collector/backends/prometheus.py index 1bc3ff4..31f3122 100644 --- a/osm_mon/collector/backends/prometheus.py +++ b/osm_mon/collector/backends/prometheus.py @@ -43,16 +43,17 @@ class PrometheusBackend(BaseBackend): def handle(self, metrics: List[Metric]): log.debug('handle') log.debug('metrics: %s', metrics) - prometheus_metrics = [] + prometheus_metrics = {} for metric in metrics: - prometheus_metric = GaugeMetricFamily( - OSM_METRIC_PREFIX + metric.name, - 'OSM metric', - labels=['ns_id', 'vnf_member_index', 'vdu_name'] - ) - prometheus_metric.add_metric([metric.nsr_id, metric.vnf_member_index, metric.vdur_name], metric.value) - prometheus_metrics.append(prometheus_metric) - self.custom_collector.metrics = prometheus_metrics + if metric.name not in prometheus_metrics: + prometheus_metrics[metric.name] = GaugeMetricFamily( + OSM_METRIC_PREFIX + metric.name, + 'OSM metric', + labels=['ns_id', 'vnf_member_index', 'vdu_name'] + ) + prometheus_metrics[metric.name].add_metric([metric.nsr_id, metric.vnf_member_index, metric.vdur_name], + metric.value) + self.custom_collector.metrics = prometheus_metrics.values() def _start_exporter(self, port): log.debug('_start_exporter') -- 2.25.1