Skip to content

Instantly share code, notes, and snippets.

@bcomnes
Created April 1, 2022 20:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bcomnes/8daac8bb7e8f6377f101aa5769d277d8 to your computer and use it in GitHub Desktop.
Save bcomnes/8daac8bb7e8f6377f101aa5769d277d8 to your computer and use it in GitHub Desktop.
import fp from 'fastify-plugin'
import Fastify from 'fastify'
/**
* This plugins adds promethius metrics
*
* @see https://gitlab.com/m03geek/fastify-metrics
*/
export default fp(async function (fastify, opts) {
fastify.register(import('fastify-metrics'), {})
const promServer = Fastify({
logger: true
})
promServer.route({
url: '/metrics',
method: 'GET',
logLevel: 'info',
schema: {
// hide route from swagger plugins
hide: true
},
handler: async (_, reply) => {
reply.type('text/plain').send(await fastify.metrics.client.register.metrics())
}
})
const start = async () => {
try {
await promServer.listen(9091)
} catch (err) {
promServer.log.error(err)
process.exit(1)
}
}
await start()
},
{
name: 'prom',
dependencies: ['env']
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment