Skip to content

Commit 699cde2

Browse files
authored
Prometheus cleanup (#3583)
* Update prometheus metrics documentation * Return 404 as default case for prometheus server * Fix lint error
1 parent a930add commit 699cde2

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

packages/client/README.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ dist/bin/cli.js --d
308308
## Metrics
309309
310310
The client can optionally collect metrics using the Prometheus metrics platform and expose them via an HTTP endpoint with the following CLI flags.
311-
The current metrics that are reported by the client can be found [here](./src/util//metrics.ts).
311+
The current metrics that are reported by the client can be found at the default port and route: `localhost:8000/metrics`.
312312
313313
```sh
314314
# npm installation
@@ -318,8 +318,6 @@ ethereumjs --prometheus
318318
npm run client:start:ts -- --prometheus --prometheusPort=9123
319319
```
320320
321-
Note: The Prometheus endpoint runs on port 8000 by default
322-
323321
## API
324322
325323
[API Reference](./docs/README.md)

packages/client/bin/cli.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1122,10 +1122,16 @@ async function run() {
11221122
const reqUrl = new url.URL(req.url, `http://${req.headers.host}`)
11231123
const route = reqUrl.pathname
11241124

1125-
if (route === '/metrics') {
1126-
// Return all metrics in the Prometheus exposition format
1127-
res.setHeader('Content-Type', register.contentType)
1128-
res.end(await register.metrics())
1125+
switch (route) {
1126+
case '/metrics':
1127+
// Return all metrics in the Prometheus exposition format
1128+
res.setHeader('Content-Type', register.contentType)
1129+
res.end(await register.metrics())
1130+
break
1131+
default:
1132+
res.statusCode = 404
1133+
res.end('Not found')
1134+
return
11291135
}
11301136
})
11311137
// Start the HTTP server which exposes the metrics on http://localhost:${args.prometheusPort}/metrics

0 commit comments

Comments
 (0)