Skip to content

Instantly share code, notes, and snippets.

@dyladan
Forked from luebken/app.js
Last active May 14, 2020 17:29
Show Gist options
  • Select an option

  • Save dyladan/a3294cd038ff8ff8ebf73a456c6e9903 to your computer and use it in GitHub Desktop.

Select an option

Save dyladan/a3294cd038ff8ff8ebf73a456c6e9903 to your computer and use it in GitHub Desktop.
const { PrometheusExporter } = require('@opentelemetry/exporter-prometheus');
const { MeterProvider } = require('@opentelemetry/metrics');
const { Resource } = require('@opentelemetry/resources');
// Add your port and startServer to the Prometheus options
const options = {port: 9464, startServer: true};
const exporter = new PrometheusExporter(options);
const resource = new Resource({
'k8s.io/container/name': 'c1',
'k8s.io/namespace/name': 'default',
'k8s.io/pod/name': 'pod-xyz-123',
});
// Register the exporter
const meter = new MeterProvider({
exporter,
interval: 1000,
resource: resource
}).getMeter('example-prometheus');
// Now, start recording data
const counter = meter.createCounter('metric_name', {
labelKeys: ['pid', 'k8siocontainername'], // <= throws new Error('Invalid label name');
description: 'Example of a counter'
});
counter.add(10, { pid: process.pid, k8siocontainername: "" });
// Record data using Instrument: It is recommended to keep a reference to the Bound Instrument instead of
// always calling `bind()` method for every operations.
const boundCounter = counter.bind({ pid: process.pid, k8siocontainername: "" });
boundCounter.add(10);
console.log("started server at :9464")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment