How to use the prom-client.Registry 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 tvvignesh / node-skeleton / src / app / controllers / metrics.server.controller.ts View on Github external
// let config = require('../../config/config');
const client = require('prom-client');

const collectDefaultMetrics = client.collectDefaultMetrics;
const register = new client.Registry();

/**
 * COLLECT DEFAULT METRICS FOR THE PROCESS
 * https://prometheus.io/docs/instrumenting/writing_clientlibs/#standard-and-runtime-collectors
 */

collectDefaultMetrics({
    timeout: 5000,
    register: register
});

/**
 * METRIC DEFINITIONS
 */

const testCounter = new client.Counter({
github timoa / app-stores-prometheus-exporter / src / lib / prometheus.js View on Github external
const client = require('prom-client');

// Stores
const itunes = require('app-store-scraper');
const gplay = require('google-play-scraper');

// Config files
const config = require('../../config/config.json');
const apps = require('../../config/apps.json');
const metrics = require('../config/metrics.json');

const register = new client.Registry();

// Collect Scrape Metrics (duration, memory/CPU used, etc.)
// https://prometheus.io/docs/instrumenting/writing_exporters/#metrics-about-the-scrape-itself
client.collectDefaultMetrics({ register });

const gauges = {};

/**
 * Get enabled metrics from the config file
 * and compatible based on the store
 *
 * @param {String} store
 * @returns
 */
function getEnabledMetrics(store) {
  const enabledMetrics = [];
github RisingStack / opentracing-metrics-tracer / src / reporters / PrometheusReporter.js View on Github external
constructor ({ ignoreTags = {} } = {}) {
    this._registry = new Prometheus.Registry()
    this._options = {
      ignoreTags
    }

    // Initialize metrics
    this._metricsOperationDurationSeconds()
  }
github badges / shields / core / server / prometheus-metrics.js View on Github external
constructor() {
    this.register = new prometheus.Registry()
    this.counters = {
      numRequests: new prometheus.Counter({
        name: 'service_requests_total',
        help: 'Total service requests',
        labelNames: ['category', 'family', 'service'],
        registers: [this.register],
      }),
      responseTime: new prometheus.Histogram({
        name: 'service_response_millis',
        help: 'Service response time in milliseconds',
        // 250 ms increments up to 2 seconds, then 500 ms increments up to 8
        // seconds, then 1 second increments up to 15 seconds.
        buckets: [
          250,
          500,
          750,
github QwantResearch / erdapfel / bin / app.js View on Github external
/* globals require, process, __dirname, module */

const express = require('express');
const yaml = require('node-yaml');
const path = require('path');
const expressStaticGzip = require('express-static-gzip');
const bunyan = require('bunyan');
const finalhandler = require('finalhandler');
const promClient = require('prom-client');
const fakePbf = require('./middlewares/fake_pbf/index');
const compression = require('compression');
const mapStyle = require('./middlewares/map_style');
const getReqSerializer = require('./serializers/request');

const app = express();
const promRegistry = new promClient.Registry();

function App(config) {
  const openSearch = require('./middlewares/opensearch/index')(config);
  const constants = yaml.readSync('../config/constants.yml');
  const languages = constants.languages;
  const router = express.Router();

  this.logger = bunyan.createLogger({
    name: 'erdapfel',
    stream: process.stdout,
    level: process.env.NODE_ENV === 'test' ? 'warn' : 'info',
    serializers: {
      req: getReqSerializer(config),
      err: bunyan.stdSerializers.err,
    },
  });
github brave-intl / bat-ledger / bat-utils / lib / runtime-prometheus.js View on Github external
function Prometheus (config, runtime) {
  if (!(this instanceof Prometheus)) {
    return new Prometheus(config, runtime)
  }

  const { prometheus } = config
  if (!prometheus) return

  const { label: dyno } = prometheus
  this.config = prometheus
  this.register = new client.Registry()
  this.client = client
  this.runtime = runtime
  this.metrics = {}
  this.shared = {}
  this.listenerId = `${listenerPrefix}${dyno}`

  this.register.setDefaultLabels({ dyno })

  const timeout = 10000
  this.timeout = timeout
  setInterval(() => this.maintenance(), timeout)
  process.on('exit', () => {
    try {
      this.quit()
    } catch (e) {
      this.runtime.captureException(e)
github interledgerjs / rafiki / src / services / stats.ts View on Github external
constructor () {
    this.registry = new (Prometheus.Registry)()

    this.incomingDataPackets = new PeerCounter({
      name: 'ilp_connector_incoming_ilp_packets',
      help: 'Total number of incoming ILP packets',
      labelNames: [ 'result', 'code'],
      registers: [this.registry]
    })

    this.incomingDataPacketValue = new PeerCounter({
      name: 'ilp_connector_incoming_ilp_packet_value',
      help: 'Total value of incoming ILP packets',
      labelNames: [ 'result', 'code'],
      registers: [this.registry]
    })

    this.outgoingDataPackets = new PeerCounter({
github ChainSafe / lodestar / packages / lodestar / src / metrics / metrics.ts View on Github external
public constructor(opts: IMetricsOptions) {
    this.opts = opts;
    this.registry = new Registry();
  }
github vtex / node-vtex-api / src / service / worker / runtime / builtIn / middlewares.ts View on Github external
export const prometheusLoggerMiddleware = () => {
  const register = new Registry()
  const gauge = new Gauge({ name: 'io_http_requests_current', help: 'The current number of requests in course.' })
  register.registerMetric(gauge)
  collectDefaultMetrics({ register })
  const startGcStats = gcStats(register)
  startGcStats()
  return async (ctx: ServiceContext, next: () => Promise) => {
    if (ctx.request.path !== '/metrics') {
      gauge.inc(1)
      await next()
      gauge.dec(1)
      return
    }
    ctx.set('Content-Type', register.contentType)
    ctx.body = register.metrics()
    ctx.status = 200
  }