Created
April 1, 2022 20:07
-
-
Save bcomnes/8daac8bb7e8f6377f101aa5769d277d8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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