From 525c800b5fc756fcffaa4d24801aae7b71f7176d Mon Sep 17 00:00:00 2001 From: Amir Date: Mon, 12 Aug 2024 22:21:53 -0700 Subject: [PATCH 1/3] Update prometheus metrics documentation --- packages/client/README.md | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/packages/client/README.md b/packages/client/README.md index 5eb589fe0f..42465bb9ba 100644 --- a/packages/client/README.md +++ b/packages/client/README.md @@ -308,7 +308,7 @@ dist/bin/cli.js --d ## Metrics The client can optionally collect metrics using the Prometheus metrics platform and expose them via an HTTP endpoint with the following CLI flags. -The current metrics that are reported by the client can be found [here](./src/util//metrics.ts). +The current metrics that are reported by the client can be found at the default port and route: `localhost:8000/metrics`. ```sh # npm installation @@ -318,8 +318,6 @@ ethereumjs --prometheus npm run client:start:ts -- --prometheus --prometheusPort=9123 ``` -Note: The Prometheus endpoint runs on port 8000 by default - ## API [API Reference](./docs/README.md) From d2fa1bab5f231448e12701b1c82f7b3c7451a8b0 Mon Sep 17 00:00:00 2001 From: Amir Date: Mon, 12 Aug 2024 22:22:19 -0700 Subject: [PATCH 2/3] Return 404 as default case for prometheus server --- packages/client/bin/cli.ts | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/packages/client/bin/cli.ts b/packages/client/bin/cli.ts index 4b2d1c1ba1..6bf997a1c7 100755 --- a/packages/client/bin/cli.ts +++ b/packages/client/bin/cli.ts @@ -1122,10 +1122,15 @@ async function run() { const reqUrl = new url.URL(req.url, `http://${req.headers.host}`) const route = reqUrl.pathname - if (route === '/metrics') { - // Return all metrics in the Prometheus exposition format - res.setHeader('Content-Type', register.contentType) - res.end(await register.metrics()) + switch (route) { + case '/metrics': + // Return all metrics in the Prometheus exposition format + res.setHeader('Content-Type', register.contentType) + res.end(await register.metrics()) + default: + res.statusCode = 404 + res.end('Not found') + return } }) // Start the HTTP server which exposes the metrics on http://localhost:${args.prometheusPort}/metrics From a7f099aac88350ceb5a22b244e7bfaa611c3e082 Mon Sep 17 00:00:00 2001 From: Amir Date: Mon, 12 Aug 2024 22:24:26 -0700 Subject: [PATCH 3/3] Fix lint error --- packages/client/bin/cli.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/client/bin/cli.ts b/packages/client/bin/cli.ts index 6bf997a1c7..1bd8c5e2e0 100755 --- a/packages/client/bin/cli.ts +++ b/packages/client/bin/cli.ts @@ -1127,6 +1127,7 @@ async function run() { // Return all metrics in the Prometheus exposition format res.setHeader('Content-Type', register.contentType) res.end(await register.metrics()) + break default: res.statusCode = 404 res.end('Not found')