How to use @opencensus/exporter-prometheus - 3 common examples

To help you get started, we’ve selected a few @opencensus/exporter-prometheus 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 magma / magma / symphony / app / fbcnms-projects / platform-server / scripts / server.js View on Github external
import logging from '@fbcnms/logging';
import tracing from '@opencensus/nodejs';
import {B3Format} from '@opencensus/propagation-b3';

import {JaegerTraceExporter} from '@opencensus/exporter-jaeger';
import {PrometheusStatsExporter} from '@opencensus/exporter-prometheus';
import {globalStats} from '@opencensus/core';
import {registerAllViews} from '@opencensus/instrumentation-http';
import {runMigrations} from './runMigrations';

const {sequelize} = require('@fbcnms/sequelize-models');
const logger = logging.getLogger(module);
const port = parseInt(process.env.PORT || 80);

// Configure metrics
const prometheusExporter = new PrometheusStatsExporter({
  startServer: true,
  logger,
});
globalStats.registerExporter(prometheusExporter);
registerAllViews(globalStats);

let jaegerExporter = null;
if (process.env.TELEMETRY_TRACE_EXPORTER == 'jaeger') {
  if (
    !process.env.JAEGER_AGENT_ENDPOINT &&
    !process.env.JAEGER_COLLECTOR_ENDPOINT
  ) {
    throw new Error(
      'When using TELEMETRY_TRACE_EXPORTER = "jaeger", you ' +
        'must set either JAEGER_AGENT_ENDPOINT or JAEGER_COLLECTOR_ENDPOINT',
    );
github census-instrumentation / opencensus-node / examples / stats / exporter / prometheus.js View on Github external
*/

/**
 * This is an example of exporting a custom metric from
 * OpenCensus to Prometheus.
 */

const { globalStats, MeasureUnit, AggregationType, TagMap } = require('@opencensus/core');
const { PrometheusStatsExporter } = require('@opencensus/exporter-prometheus');

const fs = require('fs');
const readline = require('readline');

// [START setup_exporter]
// Enable OpenCensus exporters to export metrics to Prometheus Monitoring.
const exporter = new PrometheusStatsExporter({
  // Metrics will be exported on https://localhost:{port}/metrics
  port: 9464,
  startServer: true
});

// Pass the created exporter to global Stats
globalStats.registerExporter(exporter);
// [END setup_exporter]

// The latency in milliseconds
const mLatencyMs = globalStats.createMeasureDouble(
  'repl/latency',
  MeasureUnit.MS,
  'The latency in milliseconds per REPL loop'
);
github thesandlord / Istio101 / code / code-opencensus-full / index.js View on Github external
host: jaeger_host,
    port: jaeger_port,
	serviceName: service_name,
});

tracing.start({
	propagation: b3,
	samplingRate: 1.0,
    exporter: exporter
});


// Set up Prometheus
const prometheus = require('@opencensus/exporter-prometheus');

const prometheusExporter = new prometheus.PrometheusStatsExporter({
    startServer: true
})

// Set up custom stats
const stats = new opencensus.Stats()
const tags = {ServiceName: service_name};
const tagKeys = Object.keys(tags);

const fibCount = stats.createMeasureInt64('fib function invocation', '1')
stats.createView('fib_count', fibCount, 0, tagKeys,'number of fib functions calls over time', null)

stats.registerExporter(prometheusExporter)

// End of OpenCensus setup ----------------------------------------------------------------------------

@opencensus/exporter-prometheus

OpenCensus Exporter Prometheus allows user to send collected stats to Prometheus

Apache-2.0
Latest version published 3 years ago

Package Health Score

56 / 100
Full package analysis

Popular @opencensus/exporter-prometheus functions