From 28aaded575c858a4960768ee62118a66ab9559ce Mon Sep 17 00:00:00 2001 From: namikmesic Date: Wed, 5 Oct 2022 11:48:13 +0200 Subject: [PATCH] aliasAdd exporter healthcheck metric (#28) * Add exporter healthcheck metric * Yapf --- src/collectors/evm.py | 4 +--- src/collectors/ws.py | 1 + src/exporter.py | 13 ++++++++++++- src/settings.py | 1 + 4 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/collectors/evm.py b/src/collectors/evm.py index 945a806..d524119 100644 --- a/src/collectors/evm.py +++ b/src/collectors/evm.py @@ -47,9 +47,7 @@ async def _probe(self) -> results: results.record_head_count(self.url, self.sub.head_counter) results.record_disconnects(self.url, self.sub.disconnects) except asyncio.exceptions.TimeoutError: - logger.error( - f"Timed out while trying to establish websocket connection. Current response_timeout value in config: {cfg.response_timeout}.", - url=self.stripped_url) + logger.error(f"Timed out while trying to establish websocket connection.", url=self.stripped_url) results.record_health(self.url, False) except Exception as exc: results.record_health(self.url, False) diff --git a/src/collectors/ws.py b/src/collectors/ws.py index 9fb192f..7e30761 100644 --- a/src/collectors/ws.py +++ b/src/collectors/ws.py @@ -34,6 +34,7 @@ async def _subscribe(self): try: # When we establish connection, we arm the first_time boolean, so we can record disconnect if it occurs. self.first_disconnect = True + logger.info("Subscription connection established.", url=self.stripped_url) await websocket.send(json.dumps(self.payload)) await self._message_counter(websocket) except websockets.exceptions.ConnectionClosed: diff --git a/src/exporter.py b/src/exporter.py index 6c8925e..e4075bd 100644 --- a/src/exporter.py +++ b/src/exporter.py @@ -11,7 +11,7 @@ from collectors.starkware import starkware_collector from settings import logger, cfg from metrics_processor import results -from settings import logger +from settings import logger, cfg class prom_registry(object): @@ -84,6 +84,9 @@ def _instantiate_starkware(self): self.collectors.append(starkware_collector(item)) self.labels = self.collectors[0].labels + def _report_exporter_health(self, health_metric): + health_metric.add_metric([cfg.blockchain], True) + def collect(self): metrics = { "brpc_health": @@ -143,6 +146,14 @@ def collect_metrics(prom_collector): # Only yield metric if samples were provided by the probe if len(metric.samples) > 0: yield metric + # The last step is to report exporter health + # This metric will be used to monitor if exporter is alive and forwarding metrics to prometheus endpoints. + exporter_health_metric = GaugeMetricFamily( + 'brpc_exporter_health', + 'Returns 1 if exporter was able to finalise scraping loop without exceptions.', + labels=['blockchain']) + self._report_exporter_health(exporter_health_metric) + yield exporter_health_metric def dummy_report(environ, start_fn): diff --git a/src/settings.py b/src/settings.py index 8e7686e..c625c82 100644 --- a/src/settings.py +++ b/src/settings.py @@ -16,6 +16,7 @@ def __init__(self, config_file_path: str, validation_file_path: str): self.configuration = self._load_configuration_file(config_file_path) self._populate_endpoints_metadata() self._populate_chain_id_metadata() + self.blockchain = self.configuration['blockchain'] self.endpoints = self.configuration['endpoints'] try: