How to use the prom-client.Pushgateway 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 hipages / inceptum / src / metrics / Metrics.ts View on Github external
static setup(appName: string, context: Context) {
    const defaultMetrics = prometheus.defaultMetrics;

    // Skip `osMemoryHeap` probe, and probe every 5th second.
    const defaultInterval = defaultMetrics(['osMemoryHeap'], 10000);
    process.on('exit', () => { clearInterval(defaultInterval); });

    if (context.hasConfig('metrics.gateway') &&
      context.hasConfig('metrics.gateway.active') &&
      context.getConfig('metrics.gateway.active')
    ) {
      const gateway = new prometheus.Pushgateway(context.getConfig('metrics.gateway.hostport'));
      const tags = {
        jobName: 'msPush',
        appName,
      };
      const interval = setInterval(() => {
        gateway.pushAdd(tags, (err) => {
          if (err) {
            logger.error({ err }, `There was an error pushing stats to the metrics gateway: ${context.getConfig('metrics.gateway.hostport')}`);
          }
        });
      });
      process.on('exit', () => {
        clearInterval(interval);
        gateway.pushAdd(tags, (err) => {
          if (err) {
            logger.error({ err }, 'There was an error trying to push stats one last time. Will try to delete anyway');
github clusterio / factorioClusterio / master.js View on Github external
});

require("./routes.js")(app);
require("./routes/api/getPictures.js")(app);
// Set folder to serve static content from (the website)
app.use(express.static('static'));
// mod downloads
app.use(express.static(masterModFolder));

// set up logging software
const prometheusPrefix = "clusterio_";
const Prometheus = require('prom-client');
const expressPrometheus = require('express-prometheus-request-metrics');
Prometheus.collectDefaultMetrics({ timeout: 10000 }); // collects RAM usage etc every 10 s
if(!config.disablePrometheusPushgateway){
	const pushgateway = new Prometheus.Pushgateway('http://hme.danielv.no:9091');
	setInterval(() => {
		registerMoreMetrics();
		pushgateway.push({ jobName: 'clusterio', groupings: {instance: config.publicIP + ":" + config.masterPort, owner: config.username}}, function(err, resp, body) {})
	}, 15000)
}

// collect express request durations ms
app.use(expressPrometheus(Prometheus));

const endpointHitCounter = new Prometheus.Gauge({
	name: prometheusPrefix+'endpoint_hit_gauge',
	help: "How many requests a particular endpoint has gotten",
	labelNames: ['route'],
});
const prometheusConnectedInstancesCounter = new Prometheus.Gauge({
	name: prometheusPrefix+'connected_instaces_gauge',
github hipages / inceptum / src / metrics / Metrics.ts View on Github external
static setup(jobName) {
    const defaultMetrics = Prometheus.defaultMetrics;

    // Skip `osMemoryHeap` probe, and probe every 5th second.
    const defaultInterval = defaultMetrics(['osMemoryHeap'], 10000);
    process.on('exit', () => { clearInterval(defaultInterval); });

    if (Context.hasConfig('metrics.gateway') &&
      Context.hasConfig('metrics.gateway.active') &&
      Context.getConfig('metrics.gateway.active')
    ) {
      const gateway = new Prometheus.Pushgateway(Object.assign(Context.getConfig('metrics.gateway.hostport'), { timeout: 2000 }));
      const tags = {
        jobName
      };
      const interval = setInterval(() => {
        gateway.pushAdd(tags, (err) => {
          if (err) {
            logger.error({ err }, `There was an error pushing stats to the metrics gateway: ${Context.getConfig('metrics.gateway.hostport')}`);
          }
        });
      });
      process.on('exit', () => {
        clearInterval(interval);
        gateway.pushAdd(tags, (err) => {
          if (err) {
            logger.error({ err }, 'There was an error trying to push stats one last time. Will try to delete anyway');
          }
github ChainSafe / lodestar / packages / lodestar / src / metrics / server / push.ts View on Github external
public async start(): Promise {
    this.gateway = new Pushgateway(this.opts.gatewayUrl as string, {}, this.metrics.registry);
  }
  public async stop(): Promise {
github Verivox / lighthouse-monitor / src / receivers / push-prometheus.js View on Github external
constructor(pushgw) {
        super()

        if(!pushgw) {
            throw new Error('PushPrometheus requires a pushgateway url')
        }

        this.pushgw = new prom.Pushgateway(pushgw)
    }
github strongloop / loopback-next / extensions / metrics / src / observers / metrics.push.observer.ts View on Github external
start() {
    const gwConfig = this.options.pushGateway;
    if (!gwConfig) return;
    this.gateway = new Pushgateway(gwConfig.url);
    this.interval = setInterval(() => {
      this.gateway.pushAdd({jobName: 'loopback'}, () => {});
    }, gwConfig.interval ?? 5000);
  }
github cliqz-oss / browser-core / benchmarks / post_results.js View on Github external
/*!
 * Copyright (c) 2014-present Cliqz GmbH. All rights reserved.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at https://mozilla.org/MPL/2.0/.
 */

const fs = require('fs');
const client = require('prom-client');
const gateway = new client.Pushgateway('http://pushgateway-ddns.cliqz.discover:9091');

const testNames = [
  'new_profile',
  'startup',
  'wr_all',
  'wr_antitracking',
  'wr_adblocker',
  'wr_base'
];
const labelNames = ['config', 'branch', 'benchmark', 'commit']
const metrics = {
  cputime: new client.Gauge({
    name: 'extension_benchmark_cputime',
    help: 'CPU time taken for a benchmark.',
    labelNames,
  }),