From f9f7bf2f368bf83c1881edc1727c5875d60e663a Mon Sep 17 00:00:00 2001 From: nicolargo Date: Fri, 12 Apr 2019 11:50:47 +0200 Subject: [PATCH] Too less data using prometheus exporter #1462 --- conf/glances.conf | 15 +++++++++------ glances/exports/glances_prometheus.py | 13 ++++++++----- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/conf/glances.conf b/conf/glances.conf index 8078c8fe..bb23c133 100644 --- a/conf/glances.conf +++ b/conf/glances.conf @@ -450,20 +450,23 @@ prefix=G # https://prometheus.io # Create a Prometheus exporter listening on localhost:9091 (default configuration) # Metric are exporter using the following name: -# __ (all specials character are replaced by '_') +# __{labelkey:labelvalue} # Note: You should add this exporter to your Prometheus server configuration: # scrape_configs: # - job_name: 'glances_exporter' # scrape_interval: 5s # static_configs: # - targets: ['localhost:9091'] +# +# Labels will be added for all measurements (default is src:glances) +# labels=foo:bar,spam:eggs +# You can also use dynamic values +# labels=system:`uname -s` +# host=localhost port=9091 -prefix=glances -# Labels will be added for all measurements -#labels=foo:bar,spam:eggs -# You can also use dynamic values -#labels=system:`uname -s` +#prefix=glances +#labels=src:glances [restful] # Configuration for the --export RESTful option diff --git a/glances/exports/glances_prometheus.py b/glances/exports/glances_prometheus.py index 68fa3123..eb15768c 100644 --- a/glances/exports/glances_prometheus.py +++ b/glances/exports/glances_prometheus.py @@ -39,10 +39,6 @@ class Export(GlancesExport): """Init the Prometheus export IF.""" super(Export, self).__init__(config=config, args=args) - # Optionals configuration keys - self.prefix = 'glances' - self.labels = None - # Load the Prometheus configuration file section self.export_enable = self.load_conf('prometheus', mandatories=['host', 'port'], @@ -50,6 +46,13 @@ class Export(GlancesExport): if not self.export_enable: sys.exit(2) + # Optionals configuration keys + if self.prefix is None: + self.prefix = 'glances' + + if self.labels is None: + self.labels = 'src:glances' + # Init the metric dict # Perhaps a better method is possible... self._metric_dict = {} @@ -77,7 +80,7 @@ class Export(GlancesExport): # Write metrics to the Prometheus exporter for k, v in iteritems(data): # Prometheus metric name: prefix_ - metric_name = self.prefix + self.METRIC_SEPARATOR + name + self.METRIC_SEPARATOR + k + metric_name = self.prefix + self.METRIC_SEPARATOR + str(name) + self.METRIC_SEPARATOR + str(k) # Prometheus is very sensible to the metric name # See: https://prometheus.io/docs/practices/naming/ for c in ['.', '-', '/', ' ']: