Skip to content

Commit

Permalink
aliasAdd exporter healthcheck metric (#28)
Browse files Browse the repository at this point in the history
* Add exporter healthcheck metric

* Yapf
  • Loading branch information
namikmesic authored Oct 5, 2022
1 parent 41972f1 commit 28aaded
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 4 deletions.
4 changes: 1 addition & 3 deletions src/collectors/evm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions src/collectors/ws.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
13 changes: 12 additions & 1 deletion src/exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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":
Expand Down Expand Up @@ -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):
Expand Down
1 change: 1 addition & 0 deletions src/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 28aaded

Please sign in to comment.