diff --git a/experimental/examples/prometheus/README.md b/experimental/examples/prometheus/README.md index 398427baecd..f82f2fc4843 100644 --- a/experimental/examples/prometheus/README.md +++ b/experimental/examples/prometheus/README.md @@ -60,6 +60,7 @@ If you are using the default configurations, the prometheus client will be avail
+ ## Useful links diff --git a/experimental/examples/prometheus/images/prom-gauge.png b/experimental/examples/prometheus/images/prom-gauge.png new file mode 100644 index 00000000000..1f530a1c194 Binary files /dev/null and b/experimental/examples/prometheus/images/prom-gauge.png differ diff --git a/experimental/examples/prometheus/index.js b/experimental/examples/prometheus/index.js index cd267db0198..8f8dd96836d 100644 --- a/experimental/examples/prometheus/index.js +++ b/experimental/examples/prometheus/index.js @@ -39,6 +39,23 @@ observableCounter.addCallback(observableResult => { observableResult.observe(counter, attributes); }); +const randomMetricPromise = async () => + new Promise(resolve => + setTimeout(resolve(Math.floor(Math.random() * 100)), 50) + ); + +const observableGauge = meter.createObservableGauge( + 'observable_gauge_requests', + { + description: 'Example of an ObservableGauge', + } +); +// Callbacks are run when metrics are scraped +observableGauge.addCallback(async observableResult => { + const value = await randomMetricPromise(); + observableResult.observe(value, attributes); +}); + // Record metrics setInterval(() => { counter++;