How to use the prom-client.register 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 Zooz / prometheus-api-metrics / src / metrics-middleware.js View on Github external
setupOptions.excludeRoutes = excludeRoutes || [];
        setupOptions.includeQueryParams = includeQueryParams;
        setupOptions.defaultMetricsInterval = defaultMetricsInterval;

        let metricNames = {
            http_request_duration_seconds: 'http_request_duration_seconds',
            app_version: 'app_version',
            http_request_size_bytes: 'http_request_size_bytes',
            http_response_size_bytes: 'http_response_size_bytes',
            defaultMetricsPrefix: ''
        };
        metricNames = utils.getMetricNames(metricNames, useUniqueHistogramName, metricsPrefix, projectName);

        Prometheus.collectDefaultMetrics({ timeout: defaultMetricsInterval, prefix: `${metricNames.defaultMetricsPrefix}` });

        if (!Prometheus.register.getSingleMetric(metricNames.app_version)) {
            const version = new Prometheus.Gauge({
                name: metricNames.app_version,
                help: 'The service version by package.json',
                labelNames: ['version', 'major', 'minor', 'patch']
            });

            const versionSegments = appVersion.split('.').map(Number);
            version.labels(appVersion, versionSegments[0], versionSegments[1], versionSegments[2]).set(1);
        }

        setupOptions.responseTimeHistogram = Prometheus.register.getSingleMetric(metricNames.http_request_duration_seconds) || new Prometheus.Histogram({
            name: metricNames.http_request_duration_seconds,
            help: 'Duration of HTTP requests in seconds',
            labelNames: ['method', 'route', 'code'],
            // buckets for response time from 1ms to 500ms
            buckets: durationBuckets || [0.001, 0.005, 0.015, 0.05, 0.1, 0.2, 0.3, 0.4, 0.5]
github hemerajs / hemera / packages / hemera-prometheus / index.js View on Github external
server.get('/metrics', (req, res) => {
      res.set('Content-Type', Prom.register.contentType)
      res.end(Prom.register.metrics())
    })
  }
github slanatech / swagger-stats / lib / swsInterface.js View on Github external
processAuth(req,res).then(function (authResult){
        if(!authResult){
            return;
        }
        res.statusCode = 200;
        res.setHeader('Content-Type', 'text/plain');
        res.end(promClient.register.metrics());
    });
}
github Zooz / prometheus-api-metrics / src / koa-middleware.js View on Github external
middleware(ctx, next) {
        if (!this.setupOptions.server && ctx.req.socket) {
            this.setupOptions.server = ctx.req.socket.server;
            this._collectDefaultServerMetrics(this.setupOptions.defaultMetricsInterval);
        }
        if (ctx.req.url === this.setupOptions.metricsRoute) {
            debug('Request to /metrics endpoint');
            ctx.set('Content-Type', Prometheus.register.contentType);
            ctx.body = Prometheus.register.metrics();
            return next();
        }
        if (ctx.req.url === `${this.setupOptions.metricsRoute}.json`) {
            debug('Request to /metrics endpoint');
            ctx.body = Prometheus.register.getMetricsAsJSON();
            return next();
        }

        ctx.req.metrics = {
            timer: this.setupOptions.responseTimeHistogram.startTimer({
                method: ctx.req.method
            }),
            contentLength: parseInt(ctx.request.get('content-length')) || 0
        };
github celo-org / celo-monorepo / packages / transaction-metrics-exporter / src / index.ts View on Github external
app.get('/metrics', (_req, res) => {
  res.send(PromClient.register.metrics())
})
github alexellis / nicehash-overwatch / prometheus / server.js View on Github external
rates.getZecRate((err,zecRate)=> {
			zecPrice.set(Number(zecRate.rate));	
                	res.end(promclient.register.metrics());
		});
            });
github scality / cloudserver / lib / utilities / monitoringHandler.js View on Github external
function routeHandler(req, res, log, cb) {
    if (req.method !== 'GET') {
        return cb(errors.BadRequest, []);
    }
    const promMetrics = client.register.metrics();
    const contentLen = Buffer.byteLength(promMetrics, 'utf8');
    res.setHeader('content-length', contentLen);
    res.setHeader('content-type', client.register.contentType);
    res.end(promMetrics);
    return undefined;
}
github slanatech / swagger-stats / lib / swsInterface.js View on Github external
processAuth(req,res).then(function (authResult){
        if(!authResult){
            return;
        }
        res.statusCode = 200;
        res.setHeader('Content-Type', 'text/plain');
        res.end(promClient.register.metrics());
    });
}
github crholliday / iota-prom-exporter / app.js View on Github external
app.get('/metrics', async (req, res) => {
    const [nodeResults,
           neighborResults] = await Promise.all([
        nodeInfo.getNodeInfo(),
        neighborInfo.getNeighborInfo()
    ])
    res.end(promclient.register.metrics())
})
github zalando-incubator / tessellate / packages / tessellate-server / src / MetricsApp.js View on Github external
    this.router.get('/metrics', observable => observable.mapTo(prometheus.register.metrics()));