fastify-metrics
Advanced tools
Comparing version 9.1.3 to 9.2.0
@@ -101,2 +101,15 @@ "use strict"; | ||
exposeMetrics() { | ||
const globalRegistry = this.deps.client.register; | ||
const defaultRegistries = this.getCustomDefaultMetricsRegistries(); | ||
const routeRegistries = this.getCustomRouteMetricsRegistries(); | ||
const routeHandler = async (_, reply) => { | ||
const merged = this.deps.client.Registry.merge([ | ||
globalRegistry, | ||
...defaultRegistries, | ||
...routeRegistries, | ||
]); | ||
const data = await merged.metrics(); | ||
return reply.type(merged.contentType).send(data); | ||
}; | ||
let routeOptions; | ||
const { endpoint } = this.deps.options; | ||
@@ -106,20 +119,20 @@ if (endpoint === null) { | ||
} | ||
const globalRegistry = this.deps.client.register; | ||
const defaultRegistries = this.getCustomDefaultMetricsRegistries(); | ||
const routeRegistries = this.getCustomRouteMetricsRegistries(); | ||
this.deps.fastify.route({ | ||
url: endpoint ?? '/metrics', | ||
method: 'GET', | ||
logLevel: 'fatal', | ||
exposeHeadRoute: false, | ||
handler: async (_, reply) => { | ||
const merged = this.deps.client.Registry.merge([ | ||
globalRegistry, | ||
...defaultRegistries, | ||
...routeRegistries, | ||
]); | ||
const data = await merged.metrics(); | ||
return reply.type(merged.contentType).send(data); | ||
}, | ||
}); | ||
if (typeof endpoint === 'string' || endpoint === undefined) { | ||
routeOptions = { | ||
url: endpoint ?? '/metrics', | ||
method: 'GET', | ||
logLevel: 'fatal', | ||
exposeHeadRoute: false, | ||
handler: routeHandler, | ||
}; | ||
} | ||
else { | ||
// endpoint is of type RouteOptions | ||
routeOptions = endpoint; | ||
// do not override the method | ||
routeOptions.method = 'GET'; | ||
routeOptions.handler = routeHandler; | ||
} | ||
// Add route | ||
this.deps.fastify.route(routeOptions); | ||
} | ||
@@ -126,0 +139,0 @@ /** Collect default prom-client metrics */ |
@@ -1,2 +0,2 @@ | ||
import { HTTPMethods } from 'fastify'; | ||
import { HTTPMethods, RouteOptions } from 'fastify'; | ||
import client, { DefaultMetricsCollectorConfiguration, HistogramConfiguration, SummaryConfiguration } from 'prom-client'; | ||
@@ -173,3 +173,3 @@ /** | ||
*/ | ||
endpoint?: string | null; | ||
endpoint?: string | null | RouteOptions; | ||
/** | ||
@@ -176,0 +176,0 @@ * Plugin name that will be registered in fastify instance. |
{ | ||
"$schema": "https://json.schemastore.org/package.json", | ||
"name": "fastify-metrics", | ||
"version": "9.1.3", | ||
"version": "9.2.0", | ||
"description": "Prometheus metrics exporter for Fastify", | ||
@@ -6,0 +6,0 @@ "keywords": [ |
@@ -126,8 +126,8 @@ # fastify-metrics | ||
| Property | Type | Default Value | | ||
| --------------------------------------------------------------------------------- | ------------------------------------------------------------------------ | ------------------- | | ||
| [defaultMetrics?](./docs/fastify-metrics.imetricspluginoptions.defaultmetrics.md) | [IDefaultMetricsConfig](./docs/fastify-metrics.idefaultmetricsconfig.md) | `{ enabled: true }` | | ||
| [endpoint?](./docs/fastify-metrics.imetricspluginoptions.endpoint.md) | string \| null | `'/metrics'` | | ||
| [name?](./docs/fastify-metrics.imetricspluginoptions.name.md) | string | `'metrics'` | | ||
| [routeMetrics?](./docs/fastify-metrics.imetricspluginoptions.routemetrics.md) | [IRouteMetricsConfig](./docs/fastify-metrics.iroutemetricsconfig.md) | `{ enabled: true }` | | ||
| Property | Type | Default Value | | ||
| --------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------- | ------------------- | | ||
| [defaultMetrics?](./docs/fastify-metrics.imetricspluginoptions.defaultmetrics.md) | [IDefaultMetricsConfig](./docs/fastify-metrics.idefaultmetricsconfig.md) | `{ enabled: true }` | | ||
| [endpoint?](./docs/fastify-metrics.imetricspluginoptions.endpoint.md) | string \| null \| [`Fastify.RouteOptions`](https://www.fastify.io/docs/latest/Reference/Routes/#routes-options) | `'/metrics'` | | ||
| [name?](./docs/fastify-metrics.imetricspluginoptions.name.md) | string | `'metrics'` | | ||
| [routeMetrics?](./docs/fastify-metrics.imetricspluginoptions.routemetrics.md) | [IRouteMetricsConfig](./docs/fastify-metrics.iroutemetricsconfig.md) | `{ enabled: true }` | | ||
@@ -134,0 +134,0 @@ #### Route metrics |
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
242548
630