-
-
Save dyladan/a3294cd038ff8ff8ebf73a456c6e9903 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', '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