2.1.0 • Published 8 years ago
knex-prometheus-exporter v2.1.0
knex-prometheus-exporter
Prometheus exporter for knex
npm i -S knex-prometheus-exporter prom-clientAPI
knexExporter
Knex exporter
Metrics:
# HELP knex_query_duration_seconds histogram of query responses
# TYPE knex_query_duration_seconds histogram
knex_query_duration_seconds_bucket{le="0.003"} 1
knex_query_duration_seconds_bucket{le="0.03"} 2
knex_query_duration_seconds_bucket{le="0.1"} 2
knex_query_duration_seconds_bucket{le="0.3"} 2
knex_query_duration_seconds_bucket{le="1.5"} 2
knex_query_duration_seconds_bucket{le="10"} 2
knex_query_duration_seconds_bucket{le="+Inf"} 2
knex_query_duration_seconds_sum 0.021
knex_query_duration_seconds_count 2
# HELP knex_query_errors_total counter of query errors with labels: error
# TYPE knex_query_errors_total counter
knex_query_errors_total 0
knex_query_errors_total{error="error message"} 1Parameters
knexKnex knex instanceoptsObject? optionsopts.registerString? register to useopts.labelsObject extra labels (optional, default{})opts.prefixString metric name prefix (optional, default"knex_")opts.queryDurarionNameString query duration metric name (histogram) (optional, default"query_duration_seconds")opts.responseTimeBucketsArray<Number> query duration buckets (optional, default[0.003,0.03,0.1,0.3,1.5,10])opts.queryErrorNameString query errorr total name (counter) (optional, default"query_errors_total")opts.queryErrorWithErrorLabelBoolean collect err.message as "error" label (optional, defaulttrue)
Examples
const promClient = require('prom-client');
const Knex = require('knex');
const knexExporter = require('knex-prometheus-exporter');
const knex = Knex({
client: 'mysql'
...
});
const exporter = knexExporter(knex);
console.log(promClient.register.metrics())
// =>
// # HELP knex_query_duration_seconds histogram of query responses
// # TYPE knex_query_duration_seconds histogram
// knex_query_duration_seconds_bucket{le="0.003"} 1
// knex_query_duration_seconds_bucket{le="0.03"} 2
// knex_query_duration_seconds_bucket{le="0.1"} 2
// knex_query_duration_seconds_bucket{le="0.3"} 2
// knex_query_duration_seconds_bucket{le="1.5"} 2
// knex_query_duration_seconds_bucket{le="10"} 2
// knex_query_duration_seconds_bucket{le="+Inf"} 2
// knex_query_duration_seconds_sum 0.021
// knex_query_duration_seconds_count 2
// # HELP knex_query_errors_total counter of query errors with labels: error
// # TYPE knex_query_errors_total counter
// knex_query_errors_total 0
// knex_query_errors_total{error="error message"} 1
// Unsubscribe:
exporter.off();Returns Object { off, registry }- off: unscribe from metrics, registry: prom-client registry