fastify-metrics
Advanced tools
Comparing version 9.0.2 to 9.0.3
import { FastifyInstance } from 'fastify'; | ||
import promClient from 'prom-client'; | ||
import { IMetricsPluginOptions } from './types'; | ||
import { IFastifyMetrics, IMetricsPluginOptions } from './types'; | ||
/** | ||
@@ -22,3 +22,3 @@ * Plugin constructor | ||
*/ | ||
export declare class FastifyMetrics { | ||
export declare class FastifyMetrics implements IFastifyMetrics { | ||
private readonly deps; | ||
@@ -29,2 +29,4 @@ private static getRouteSlug; | ||
private readonly methodBlacklist; | ||
private routeMetrics; | ||
/** Prom-client instance */ | ||
readonly client: typeof promClient; | ||
@@ -53,6 +55,12 @@ /** Creates metrics collector instance */ | ||
private collectDefaultMetrics; | ||
private registerRouteMetrics; | ||
/** Collect per-route metrics */ | ||
private collectRouteMetrics; | ||
/** | ||
* Initialize metrics in registries. Useful if you call `registry.clear()` to | ||
* register metrics in regisitries once again | ||
*/ | ||
initMetricsInRegistry(): void; | ||
} | ||
export {}; | ||
//# sourceMappingURL=fastify-metrics.d.ts.map |
@@ -19,4 +19,9 @@ "use strict"; | ||
this.setRouteWhitelist(); | ||
this.collectDefaultMetrics(); | ||
this.collectRouteMetrics(); | ||
if (!(this.deps.options.defaultMetrics?.enabled === false)) { | ||
this.collectDefaultMetrics(); | ||
} | ||
if (!(this.deps.options.routeMetrics?.enabled === false)) { | ||
this.routeMetrics = this.registerRouteMetrics(); | ||
this.collectRouteMetrics(); | ||
} | ||
this.exposeMetrics(); | ||
@@ -104,7 +109,2 @@ } | ||
const routeRegistries = this.getCustomRouteMetricsRegistries(); | ||
const merged = this.deps.client.Registry.merge([ | ||
globalRegistry, | ||
...defaultRegistries, | ||
...routeRegistries, | ||
]); | ||
this.deps.fastify.route({ | ||
@@ -116,4 +116,9 @@ url: endpoint ?? '/metrics', | ||
handler: async (_, reply) => { | ||
const merged = this.deps.client.Registry.merge([ | ||
globalRegistry, | ||
...defaultRegistries, | ||
...routeRegistries, | ||
]); | ||
const data = await merged.metrics(); | ||
return reply.type('text/plain').send(data); | ||
return reply.type(merged.contentType).send(data); | ||
}, | ||
@@ -124,5 +129,2 @@ }); | ||
collectDefaultMetrics() { | ||
if (this.deps.options.defaultMetrics?.enabled === false) { | ||
return; | ||
} | ||
this.deps.client.collectDefaultMetrics({ | ||
@@ -132,7 +134,3 @@ ...this.deps.options.defaultMetrics, | ||
} | ||
/** Collect per-route metrics */ | ||
collectRouteMetrics() { | ||
if (this.deps.options.routeMetrics?.enabled === false) { | ||
return; | ||
} | ||
registerRouteMetrics() { | ||
const labelNames = { | ||
@@ -168,2 +166,7 @@ method: this.deps.options.routeMetrics?.overrides?.labels?.method ?? 'method', | ||
}); | ||
return { routeHist, routeSum, labelNames }; | ||
} | ||
/** Collect per-route metrics */ | ||
collectRouteMetrics() { | ||
const { routeHist, routeSum, labelNames } = this.routeMetrics; | ||
this.deps.fastify | ||
@@ -222,4 +225,16 @@ .addHook('onRequest', (request, _, done) => { | ||
} | ||
/** | ||
* Initialize metrics in registries. Useful if you call `registry.clear()` to | ||
* register metrics in regisitries once again | ||
*/ | ||
initMetricsInRegistry() { | ||
if (!(this.deps.options.defaultMetrics?.enabled === false)) { | ||
this.collectDefaultMetrics(); | ||
} | ||
if (!(this.deps.options.routeMetrics?.enabled === false)) { | ||
this.routeMetrics = this.registerRouteMetrics(); | ||
} | ||
} | ||
} | ||
exports.FastifyMetrics = FastifyMetrics; | ||
//# sourceMappingURL=fastify-metrics.js.map |
@@ -200,4 +200,10 @@ import { HTTPMethods } from 'fastify'; | ||
export interface IFastifyMetrics { | ||
/** Prom-client instance */ | ||
client: typeof client; | ||
/** | ||
* Initialize metrics in registries. Useful if you call `registry.clear()` to | ||
* register metrics in regisitries once again | ||
*/ | ||
initMetricsInRegistry(): void; | ||
} | ||
//# sourceMappingURL=types.d.ts.map |
{ | ||
"$schema": "https://json.schemastore.org/package.json", | ||
"name": "fastify-metrics", | ||
"version": "9.0.2", | ||
"version": "9.0.3", | ||
"description": "Prometheus metrics exporter for Fastify", | ||
@@ -6,0 +6,0 @@ "keywords": [ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
240887
608