Skip to content

Commit

Permalink
Start prom metrics server in separate thread to improve performance
Browse files Browse the repository at this point in the history
  • Loading branch information
gnpar committed Sep 19, 2024
1 parent a424189 commit 7f64fde
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/eth_exporter/exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from datetime import datetime, timezone

from prometheus_async.aio import time as prom_time
from prometheus_async.aio.web import start_http_server
from prometheus_async.aio.web import start_http_server_in_thread
from web3 import AsyncWeb3
from web3.middleware import ExtraDataToPOAMiddleware, validation
from web3.providers import AsyncHTTPProvider
Expand Down Expand Up @@ -87,7 +87,7 @@ async def main():
metrics_config = MetricsConfig.load_yaml(config.METRICS_CONFIG_PATH)

# Set up the prometheus server
prom_server = await start_http_server(port=config.METRICS_PORT)
prom_server = start_http_server_in_thread(port=config.METRICS_PORT)
logger.info("Started metrics server on %s", prom_server.url)

w3 = AsyncWeb3(AsyncHTTPProvider(config.NODE_HTTPS_URL, cache_allowed_requests=True))
Expand All @@ -109,7 +109,7 @@ async def main():
await asyncio.gather(main_loop(w3, blocks_queue), worker)
finally:
logger.info("Shutting down")
await prom_server.close()
prom_server.close()
worker.cancel()


Expand Down

0 comments on commit 7f64fde

Please sign in to comment.