Created
May 14, 2020 16:39
-
-
Save luebken/a1667d915f23cbf97e9c998ab92783b8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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', 'k8s.io/container/name'], // <= throws new Error('Invalid label name'); | |
description: 'Example of a counter' | |
}); | |
counter.add(10, { pid: process.pid }); | |
// 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 }); | |
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