Skip to content

Commit 28aaded

Browse files
authored
aliasAdd exporter healthcheck metric (#28)
* Add exporter healthcheck metric * Yapf
1 parent 41972f1 commit 28aaded

File tree

4 files changed

+15
-4
lines changed

4 files changed

+15
-4
lines changed

src/collectors/evm.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,7 @@ async def _probe(self) -> results:
4747
results.record_head_count(self.url, self.sub.head_counter)
4848
results.record_disconnects(self.url, self.sub.disconnects)
4949
except asyncio.exceptions.TimeoutError:
50-
logger.error(
51-
f"Timed out while trying to establish websocket connection. Current response_timeout value in config: {cfg.response_timeout}.",
52-
url=self.stripped_url)
50+
logger.error(f"Timed out while trying to establish websocket connection.", url=self.stripped_url)
5351
results.record_health(self.url, False)
5452
except Exception as exc:
5553
results.record_health(self.url, False)

src/collectors/ws.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ async def _subscribe(self):
3434
try:
3535
# When we establish connection, we arm the first_time boolean, so we can record disconnect if it occurs.
3636
self.first_disconnect = True
37+
logger.info("Subscription connection established.", url=self.stripped_url)
3738
await websocket.send(json.dumps(self.payload))
3839
await self._message_counter(websocket)
3940
except websockets.exceptions.ConnectionClosed:

src/exporter.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from collectors.starkware import starkware_collector
1212
from settings import logger, cfg
1313
from metrics_processor import results
14-
from settings import logger
14+
from settings import logger, cfg
1515

1616

1717
class prom_registry(object):
@@ -84,6 +84,9 @@ def _instantiate_starkware(self):
8484
self.collectors.append(starkware_collector(item))
8585
self.labels = self.collectors[0].labels
8686

87+
def _report_exporter_health(self, health_metric):
88+
health_metric.add_metric([cfg.blockchain], True)
89+
8790
def collect(self):
8891
metrics = {
8992
"brpc_health":
@@ -143,6 +146,14 @@ def collect_metrics(prom_collector):
143146
# Only yield metric if samples were provided by the probe
144147
if len(metric.samples) > 0:
145148
yield metric
149+
# The last step is to report exporter health
150+
# This metric will be used to monitor if exporter is alive and forwarding metrics to prometheus endpoints.
151+
exporter_health_metric = GaugeMetricFamily(
152+
'brpc_exporter_health',
153+
'Returns 1 if exporter was able to finalise scraping loop without exceptions.',
154+
labels=['blockchain'])
155+
self._report_exporter_health(exporter_health_metric)
156+
yield exporter_health_metric
146157

147158

148159
def dummy_report(environ, start_fn):

src/settings.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ def __init__(self, config_file_path: str, validation_file_path: str):
1616
self.configuration = self._load_configuration_file(config_file_path)
1717
self._populate_endpoints_metadata()
1818
self._populate_chain_id_metadata()
19+
self.blockchain = self.configuration['blockchain']
1920
self.endpoints = self.configuration['endpoints']
2021

2122
try:

0 commit comments

Comments
 (0)