From 7b3cb41b1fe4ebde524a6397e0e89056b901a2bd Mon Sep 17 00:00:00 2001 From: Alex Vorona Date: Thu, 11 Jul 2024 07:55:17 +0100 Subject: [PATCH] limit max block lag to 60 seconds by default --- README.md | 2 ++ exporter/main.py | 6 ++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 57a034a..1423d21 100644 --- a/README.md +++ b/README.md @@ -13,3 +13,5 @@ Use following environment variables to override defaults: * `WS_URL=ws://localhost:8545` - websocket URL to connect and subscribe to new blocks * `HIST_BUCKETS=0.05,0.08,0.1,0.15,0.2,0.3,0.4,0.6,0.8,1.0,1.2,1.6,2.0,2.5,3.0,4.0,8.0,+Inf` - override prometheus histogram buckets for histogram metric +* `MAX_BLOCK_LAG=60.0` - all data above this threshold will be logged, but not added to metrics. This exporter is intended to monitor + the current block lag instead of initial sync-up/catch-up. diff --git a/exporter/main.py b/exporter/main.py index 451d712..430b772 100644 --- a/exporter/main.py +++ b/exporter/main.py @@ -17,8 +17,9 @@ def process_block(block): block_number = int(block['number'], 16) ts = time.time() lag = ts - timestamp - hist.observe(lag) - gauge.set("{:+.4f}".format(lag)) + if lag < max_block_lag: + hist.observe(lag) + gauge.set("{:+.4f}".format(lag)) print("ts=%d block=%d lag=%2.4f" % (timestamp, block_number, lag), flush=True) return @@ -74,6 +75,7 @@ async def health(self): ws_url = os.environ.get("WS_URL", "ws://localhost:8545") buckets = os.environ.get( "HIST_BUCKETS", "0.05,0.08,0.1,0.15,0.2,0.3,0.4,0.6,0.8,1.0,1.2,1.6,2.0,2.5,3.0,4.0,8.0,+Inf") + max_block_lag = float(os.environ.get("MAX_BLOCK_LAG", 60.0)) hist = Histogram('head_lag_seconds', 'Last block lag', buckets=buckets.split(','))