Skip to content

Commit 601ec14

Browse files
authored
use global metric registry
Use the global REGISTRY, in order : 1) add exporter runtime metrics (fix #9 ) 2) add more metrics later (collection time for each object type) This patch is intended to expose internal metrics on `/metrics` only for the default section (so people with multiple sections `?section=something` don't get duplicate metrics).
1 parent bd5a35b commit 601ec14

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

vmware_exporter/vmware_exporter.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
# Prometheus specific imports
3232
from prometheus_client.core import GaugeMetricFamily
3333
from prometheus_client import CollectorRegistry, generate_latest
34+
from prometheus_client.core import REGISTRY
3435

3536
from .helpers import batch_fetch_properties, get_bool_env
3637
from .defer import parallelize, run_once_property
@@ -892,8 +893,13 @@ def generate_latest_metrics(self, request):
892893
self.config[section]['ignore_ssl'],
893894
)
894895
metrics = yield collector.collect()
896+
897+
# URI /metrics?section=default
898+
if request.path = '/metrics' and section == 'default':
899+
registry = REGISTRY
900+
else:
901+
registry = CollectorRegistry()
895902

896-
registry = CollectorRegistry()
897903
registry.register(ListCollector(metrics))
898904
output = generate_latest(registry)
899905

0 commit comments

Comments
 (0)