How to use the prom-client.Summary function in prom-client

To help you get started, we’ve selected a few prom-client examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github qlik-oss / mira / src / Metrics.js View on Github external
os: process.platform,
  osRelease: os.release(),
}, 1);

// Collect default prometheus metrics every 10 seconds
const collectDefaultMetrics = prom.collectDefaultMetrics;
collectDefaultMetrics();

// Create metric histogram and summary for api response times
const responseTimeHistogram = new prom.Histogram({
  name: 'http_request_duration_seconds',
  help: `Time in seconds consumed from ${version.name} receiving a request until a response is sent per path`,
  labelNames: ['path'],
});

const responseTimeSummary = new prom.Summary({
  name: 'http_request_duration_seconds_total',
  help: `Time in seconds consumed from ${version.name} receiving a request until a response is sent in total`,
});

// function for recording time consumed for a request and adding as metric
function recordResponseTimes() {
  return async function responseTime(ctx, next) {
    const requestTime = Date.now();
    await next();
    const diff = Math.ceil((Date.now() - requestTime) / 1000);
    responseTimeSummary.observe(diff);
    responseTimeHistogram.observe({ path: ctx.request.url }, diff);
    if (diff > Config.allowedResponseTime) {
      logger.warn(`Request for endpoint ${ctx.request.url} took ${diff} s, which is longer than allowed ${Config.allowedResponseTime} s`);
    }
  };
github RocketChat / Rocket.Chat / packages / rocketchat-lib / server / lib / metrics.js View on Github external
// one sample metrics only - a counter

RocketChat.metrics.meteorMethods = new client.Summary({
	name: 'rocketchat_meteor_methods',
	help: 'summary of meteor methods count and time',
	labelNames: ['method', 'has_connection', 'has_user'],
});

RocketChat.metrics.rocketchatCallbacks = new client.Summary({
	name: 'rocketchat_callbacks',
	help: 'summary of rocketchat callbacks count and time',
	labelNames: ['hook', 'callback'],
});

RocketChat.metrics.rocketchatHooks = new client.Summary({
	name: 'rocketchat_hooks',
	help: 'summary of rocketchat hooks count and time',
	labelNames: ['hook', 'callbacks_length'],
});

RocketChat.metrics.rocketchatRestApi = new client.Summary({
	name: 'rocketchat_rest_api',
	help: 'summary of rocketchat rest api count and time',
	labelNames: ['method', 'entrypoint', 'user_agent', 'status', 'version'],
});

RocketChat.metrics.meteorSubscriptions = new client.Summary({
	name: 'rocketchat_meteor_subscriptions',
	help: 'summary of meteor subscriptions count and time',
	labelNames: ['subscription'],
});
github calzoneman / sync / src / channel / library.js View on Github external
chan.refCounter.unref("LibraryModule::handleUncache");
            return;
        }

        chan.logger.log("[library] " + user.getName() + " deleted " + data.id +
                        "from the library");
        chan.refCounter.unref("LibraryModule::handleUncache");
    });
};

const librarySearchQueryCount = new Counter({
    name: 'cytube_library_search_query_count',
    help: 'Counter for number of channel library searches',
    labelNames: ['source']
});
const librarySearchResultSize = new Summary({
    name: 'cytube_library_search_results_size',
    help: 'Summary for number of channel library results returned',
    labelNames: ['source']
});
LibraryModule.prototype.handleSearchMedia = function (user, data) {
    var query = data.query.substring(0, 100);
    var searchYT = function () {
        librarySearchQueryCount.labels('yt').inc(1, new Date());
        InfoGetter.Getters.ytSearch(query, function (e, vids) {
            if (!e) {
                librarySearchResultSize.labels('yt')
                        .observe(vids.length, new Date());
                user.socket.emit("searchResults", {
                    source: "yt",
                    results: vids
                });
github RocketChat / Rocket.Chat / packages / rocketchat-lib / server / lib / metrics.js View on Github external
labelNames: ['hook', 'callback'],
});

RocketChat.metrics.rocketchatHooks = new client.Summary({
	name: 'rocketchat_hooks',
	help: 'summary of rocketchat hooks count and time',
	labelNames: ['hook', 'callbacks_length'],
});

RocketChat.metrics.rocketchatRestApi = new client.Summary({
	name: 'rocketchat_rest_api',
	help: 'summary of rocketchat rest api count and time',
	labelNames: ['method', 'entrypoint', 'user_agent', 'status', 'version'],
});

RocketChat.metrics.meteorSubscriptions = new client.Summary({
	name: 'rocketchat_meteor_subscriptions',
	help: 'summary of meteor subscriptions count and time',
	labelNames: ['subscription'],
});

RocketChat.metrics.messagesSent = new client.Counter({ name: 'rocketchat_message_sent', help: 'cumulated number of messages sent' });
RocketChat.metrics.notificationsSent = new client.Counter({ name: 'rocketchat_notification_sent', labelNames: ['notification_type'], help: 'cumulated number of notifications sent' });

RocketChat.metrics.ddpSessions = new client.Gauge({ name: 'rocketchat_ddp_sessions_count', help: 'number of open ddp sessions' });
RocketChat.metrics.ddpAthenticatedSessions = new client.Gauge({ name: 'rocketchat_ddp_sessions_auth', help: 'number of authenticated open ddp sessions' });
RocketChat.metrics.ddpConnectedUsers = new client.Gauge({ name: 'rocketchat_ddp_connected_users', help: 'number of unique connected users' });

RocketChat.metrics.version = new client.Gauge({ name: 'rocketchat_version', labelNames: ['version'], help: 'Rocket.Chat version' });
RocketChat.metrics.migration = new client.Gauge({ name: 'rocketchat_migration', help: 'migration versoin' });
RocketChat.metrics.instanceCount = new client.Gauge({ name: 'rocketchat_instance_count', help: 'instances running' });
RocketChat.metrics.oplogEnabled = new client.Gauge({ name: 'rocketchat_oplog_enabled', labelNames: ['enabled'], help: 'oplog enabled' });
github SkeLLLa / fastify-metrics / src / index.ts View on Github external
opts.summary.registers = [register];
    }
    if (prefix) {
      defaultOpts.prefix = prefix;
      opts.histogram.name = `${prefix}${opts.histogram.name}`;
      opts.summary.name = `${prefix}${opts.summary.name}`;
    }
    Object.keys(metrics)
      .filter(opts.hasOwnProperty.bind(opts))
      .forEach((key) => {
        Object.assign(opts[key], metrics[key]);
      });

    client.collectDefaultMetrics(defaultOpts);
    const routeHist = new client.Histogram(opts.histogram);
    const routeSum = new client.Summary(opts.summary);

    if (endpoint) {
      fastify.route({
        url: endpoint,
        method: 'GET',
        schema: {hide: true},
        handler: (_, reply) => {
          const data = register
            ? register.metrics()
            : client.register.metrics();
          reply.type('text/plain').send(data);
        },
      });
    }

    fastify.addHook('onRequest', (request, _, next) => {
github RocketChat / Rocket.Chat / app / metrics / server / lib / metrics.js View on Github external
import client from 'prom-client';
import connect from 'connect';
import http from 'http';
import _ from 'underscore';
import { Meteor } from 'meteor/meteor';
import { Info } from '../../../utils';
import { Migrations } from '../../../migrations';
import { settings } from '../../../settings';
import { Statistics } from '../../../models';

client.collectDefaultMetrics();

export const metrics = {};

metrics.meteorMethods = new client.Summary({
	name: 'rocketchat_meteor_methods',
	help: 'summary of meteor methods count and time',
	labelNames: ['method', 'has_connection', 'has_user'],
});

metrics.rocketchatCallbacks = new client.Summary({
	name: 'rocketchat_callbacks',
	help: 'summary of rocketchat callbacks count and time',
	labelNames: ['hook', 'callback'],
});

metrics.rocketchatHooks = new client.Summary({
	name: 'rocketchat_hooks',
	help: 'summary of rocketchat hooks count and time',
	labelNames: ['hook', 'callbacks_length'],
});
github neo-one-suite / neo-one / packages / neo-one-monitor / src / NodeMetricsFactory.ts View on Github external
protected createSummaryInternal(options: PercentiledMetricOptions): Summary {
    return new SummaryProxy(
      this.initializeMetric(
        new prom.Summary(this.getMetricConstruct(options)),
        options,
        (metric: prom.Summary, labels: Labels) => metric.observe(labels as prom.labelValues, 0),
      ),
      options.labelNames,
    );
  }
github RocketChat / Rocket.Chat / app / metrics / server / lib / metrics.js View on Github external
export const metrics = {};

metrics.meteorMethods = new client.Summary({
	name: 'rocketchat_meteor_methods',
	help: 'summary of meteor methods count and time',
	labelNames: ['method', 'has_connection', 'has_user'],
});

metrics.rocketchatCallbacks = new client.Summary({
	name: 'rocketchat_callbacks',
	help: 'summary of rocketchat callbacks count and time',
	labelNames: ['hook', 'callback'],
});

metrics.rocketchatHooks = new client.Summary({
	name: 'rocketchat_hooks',
	help: 'summary of rocketchat hooks count and time',
	labelNames: ['hook', 'callbacks_length'],
});

metrics.rocketchatRestApi = new client.Summary({
	name: 'rocketchat_rest_api',
	help: 'summary of rocketchat rest api count and time',
	labelNames: ['method', 'entrypoint', 'user_agent', 'status', 'version'],
});

metrics.meteorSubscriptions = new client.Summary({
	name: 'rocketchat_meteor_subscriptions',
	help: 'summary of meteor subscriptions count and time',
	labelNames: ['subscription'],
});
github tvvignesh / node-skeleton / src / app / controllers / metrics.server.controller.ts View on Github external
});

const testGauge = new client.Gauge({
    name: 'gaugeName',
    help: 'gaugeHelp',
    registers: [register]
});

const testHistogram = new client.Histogram({
    name: 'histogramName',
    help: 'histogramHelp',
    labelNames: ['label1'],
    buckets: [0.1, 5, 15, 50, 100, 500]
});

const testSummary = new client.Summary({
    name: 'summaryName',
    help: 'summaryHelp'
});

/**
 * INITIALIZE METRICS
 */
const initCounters = function() {
    testCounter.inc(
        {
            label1: 'Test Label'
        },
        0
    );

    testGauge.set(0);
github calzoneman / sync / src / web / webserver.js View on Github external
function initPrometheus(app) {
    const latency = new Summary({
        name: 'cytube_http_req_duration_seconds',
        help: 'HTTP Request latency from execution of the first middleware '
                + 'until the "finish" event on the response object.',
        labelNames: ['method', 'statusCode']
    });
    const requests = new Counter({
        name: 'cytube_http_req_total',
        help: 'HTTP Request count',
        labelNames: ['method', 'statusCode']
    });

    app.use((req, res, next) => {
        const startTime = process.hrtime();
        res.on('finish', () => {
            try {
                const diff = process.hrtime(startTime);