Monitoring and Metrics - kkemple/awesome-enterprise-web-service GitHub Wiki
This app includes New Relic for application monitoring, just add the NEWRELIC_LICENSE_KEY env variable andthe app name is derived from the package.json app name.
Custom Metrics
The server object also has Statsd availble via server.statsd. Every request is also tracked by statsd. Read the docs for the hapi-statd plugin for all availble options.
Example
{
method: 'POST',
path: '/api/authenticate',
config: {
tags: ['api', 'auth'],
auth: false,
validate: {
payload: authenticationPayload,
},
handler(req, reply) {
const { email, password } = req.payload
const { User, Token } = req.server.app.models
User.authenticate(email, password)
.then((user) => Token.tokenize(user))
.then((token) => {
req.server.statsd.increment(`login.success.user.${user.id}`)
reply({
success: true,
payload: { token },
})
})
.catch((err) => {
req.server.statsd.increment(`login.fail.user.${user.id}`)
reply({
success: false,
error: err.name,
message: err.message,
stack: err.stack,
}).code(401)
})
},
},
}