I’d like to build a multi-target exporter, similar to the blackbox exporter, where it takes an IP address as part of the URL path and uses that to collect metrics from hardware devices. This would be my first time writing a Prometheus exporter. From the Python client examples, I’ve created a CustomCollector class which collects only when scraped, running with start_http_server. But I can’t figure out how to access the URL path as a variable. Is that possible with this method or do I need to use a different web server like Flask or WSGI? A very simple example is below.
from prometheus_client.core import GaugeMetricFamily, REGISTRYfrom prometheus_client.registry import Collectorfrom prometheus_client import start_http_serverimport randomimport time class CustomCollector(Collector): def collect(self): """Yield metrics only when scraped""" metrics = self.read_from_device() for metric in metrics: yield GaugeMetricFamily(metric['name'], 'help text', value=metric['value']) def read_from_device(self): """Blocking code that reads and parses data from hardware""" return [ {'name': 'request_processing_seconds', 'value': random.random()}, ] REGISTRY.register(CustomCollector()) if __name__ == '__main__': start_http_server(port=8000) while True: time.sleep(86400) -- You received this message because you are subscribed to the Google Groups "Prometheus Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to prometheus-users+unsubscr...@googlegroups.com. To view this discussion visit https://groups.google.com/d/msgid/prometheus-users/CALajkdhNnijAFTNz12_e0opP4rhvM-gQcViBXNsxcZY1ReuwQA%40mail.gmail.com.