PrometheusPlugin #

The Kuzzle plugin: Kuzzle metrics, API request durations, Node.js metrics, and a Metrics instance for the application's own metrics.

import { PrometheusPlugin } from 'kuzzle-prometheus/kuzzle';

kuzzle-prometheus/kuzzle also re-exports everything kuzzle-prometheus exports.

Constructor #

constructor(options?: PrometheusPluginOptions)

Parameters #

  • options: optional, PrometheusPluginOptions:
OptionTypeDefaultDescription
prefixstring""prepended to the application's metric names (not to Kuzzle's)
maxLabelSetsnumber1000label combinations accepted per application metric (see Keep labels bounded)

The rest of the configuration is read from the Kuzzle configuration: see Kuzzle configuration.

const prometheus = new PrometheusPlugin({ prefix: 'iot_' });
app.plugin.use(prometheus);

Properties #

metrics #

readonly metrics: Metrics

The application's Metrics instance. Declare the application's metrics on it, at startup: they are exposed with the Kuzzle metrics.

export const payloads = prometheus.metrics.counter({
  name: 'payloads_received_total',
  help: 'Payloads received from devices',
  labelNames: ['protocol'],
});

Its common labels, nodeId and other labels are set when Kuzzle initializes the plugin, from the Kuzzle configuration.

config #

config: {
  core: { monitorRequestDuration: boolean; nodeIdLabel: boolean; prefix: string; requestDurationBuckets: number[] };
  default: { enabled: boolean; prefix: string; eventLoopMonitoringPrecision: number; gcDurationBuckets: number[] };
  labels: Record<string, string>;
}

The resolved configuration, available once Kuzzle has initialized the plugin: the plugins.prometheus section merged over the defaults. labels values are converted to strings.

Methods #

serveMetrics #

serveMetrics(request: KuzzleRequest): Promise<string | undefined>

The handler of GET /_/metrics (the prometheus:metrics action). Kuzzle calls it; an application does not need to.

Exports #

ExportDescription
DEFAULT_REQUEST_DURATION_BUCKETSdefault value of core.requestDurationBuckets, in milliseconds
PrometheusPluginConfigurationtype of the plugins.prometheus section of the Kuzzle configuration
PrometheusPluginOptionstype of the constructor options