Skip to content

Commit

Permalink
limit max block lag to 60 seconds by default
Browse files Browse the repository at this point in the history
  • Loading branch information
voron committed Jul 11, 2024
1 parent ebe70c0 commit 7b3cb41
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
6 changes: 4 additions & 2 deletions exporter/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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(','))
Expand Down

0 comments on commit 7b3cb41

Please sign in to comment.