Skip to content

Commit

Permalink
feat: add start indicator (#175)
Browse files Browse the repository at this point in the history
  • Loading branch information
kalinkrustev authored Nov 29, 2024
1 parent d3146e1 commit 2344b03
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 26 deletions.
39 changes: 16 additions & 23 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@
},
"devDependencies": {
"@hapi/hapi": "^21.3.12",
"@types/node": "^22.9.3",
"@types/tape": "^5.6.4",
"@types/node": "^22.10.1",
"@types/tape": "^5.6.5",
"audit-ci": "^7.1.0",
"debug": "4.3.7",
"joi": "^17.13.3",
Expand Down
14 changes: 13 additions & 1 deletion src/metrics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,13 @@ class Metrics {
labelNames: ['method']
})

new client.Gauge({
registers: [this.getDefaultRegister()],
name: 'http_server_start',
help: 'Start indicator for the server'
}).inc()
let first = true

server.ext('onRequest', (request, h) => {
const { maxConnections = 0, maxRequestsPending = 0 } = this.getOptions()
if ((maxConnections > 0 || maxRequestsPending > 0) && request.path === '/health') {
Expand Down Expand Up @@ -266,7 +273,12 @@ class Metrics {
method: 'GET',
path: '/metrics',
handler: async (request, h) => {
return h.response(await this.getMetricsForPrometheus()).code(200).type('text/plain; version=0.0.4')
const metrics = await this.getMetricsForPrometheus()
if (first) {
this.getDefaultRegister().removeSingleMetric('http_server_start')
first = false
}
return h.response(metrics).code(200).type('text/plain; version=0.0.4')
},
options: {
tags: ['api', 'metrics'],
Expand Down

0 comments on commit 2344b03

Please sign in to comment.