Too less data using prometheus exporter #1462

pull/1471/head
nicolargo 2019-04-12 11:50:47 +02:00
parent c645ef81ae
commit f9f7bf2f36
2 changed files with 17 additions and 11 deletions

View File

@ -450,20 +450,23 @@ prefix=G
# https://prometheus.io # https://prometheus.io
# Create a Prometheus exporter listening on localhost:9091 (default configuration) # Create a Prometheus exporter listening on localhost:9091 (default configuration)
# Metric are exporter using the following name: # Metric are exporter using the following name:
# <prefix>_<plugin>_<stats> (all specials character are replaced by '_') # <prefix>_<plugin>_<stats>{labelkey:labelvalue}
# Note: You should add this exporter to your Prometheus server configuration: # Note: You should add this exporter to your Prometheus server configuration:
# scrape_configs: # scrape_configs:
# - job_name: 'glances_exporter' # - job_name: 'glances_exporter'
# scrape_interval: 5s # scrape_interval: 5s
# static_configs: # static_configs:
# - targets: ['localhost:9091'] # - 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 host=localhost
port=9091 port=9091
prefix=glances #prefix=glances
# Labels will be added for all measurements #labels=src:glances
#labels=foo:bar,spam:eggs
# You can also use dynamic values
#labels=system:`uname -s`
[restful] [restful]
# Configuration for the --export RESTful option # Configuration for the --export RESTful option

View File

@ -39,10 +39,6 @@ class Export(GlancesExport):
"""Init the Prometheus export IF.""" """Init the Prometheus export IF."""
super(Export, self).__init__(config=config, args=args) super(Export, self).__init__(config=config, args=args)
# Optionals configuration keys
self.prefix = 'glances'
self.labels = None
# Load the Prometheus configuration file section # Load the Prometheus configuration file section
self.export_enable = self.load_conf('prometheus', self.export_enable = self.load_conf('prometheus',
mandatories=['host', 'port'], mandatories=['host', 'port'],
@ -50,6 +46,13 @@ class Export(GlancesExport):
if not self.export_enable: if not self.export_enable:
sys.exit(2) 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 # Init the metric dict
# Perhaps a better method is possible... # Perhaps a better method is possible...
self._metric_dict = {} self._metric_dict = {}
@ -77,7 +80,7 @@ class Export(GlancesExport):
# Write metrics to the Prometheus exporter # Write metrics to the Prometheus exporter
for k, v in iteritems(data): for k, v in iteritems(data):
# Prometheus metric name: prefix_<glances stats name> # Prometheus metric name: prefix_<glances stats name>
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 # Prometheus is very sensible to the metric name
# See: https://prometheus.io/docs/practices/naming/ # See: https://prometheus.io/docs/practices/naming/
for c in ['.', '-', '/', ' ']: for c in ['.', '-', '/', ' ']: