feat: /metrics
This commit is contained in:
@@ -18,6 +18,23 @@ export function webappServe(watchers: Watcher[], host = 'localhost', port = 1050
|
||||
}))
|
||||
})
|
||||
|
||||
webapp.get('/metrics', (req, res) => {
|
||||
res.set('Content-Type', 'text/plain; version=0.0.4')
|
||||
|
||||
const metrics: string[] = []
|
||||
|
||||
watchers.forEach(watcher => {
|
||||
const name = watcher.name.replace(/[^a-zA-Z0-9_]/g, '_')
|
||||
const state = watcher.state
|
||||
|
||||
// Métrique d'état numérique (0=INIT, 1=OK, 2=FAILURE, 3=RECOVERED)
|
||||
const stateValue = state === 'INIT' ? 0 : state === 'OK' ? 1 : state === 'FAILURE' ? 2 : 3
|
||||
metrics.push(`dwatcher_watcher_state{name="${name}",state="${state}"} ${stateValue}`)
|
||||
})
|
||||
|
||||
res.send(metrics.join('\n') + '\n')
|
||||
})
|
||||
|
||||
webapp.use('/', express.static(path.join(__dirname, '../../dist/')))
|
||||
|
||||
webapp.listen(port, host, () => console.log(`webserver listening at http://${host}:${port}`))
|
||||
|
||||
Reference in New Issue
Block a user