Skip to content

Commit

Permalink
docs: add observableGauge to the prometheus experimental example (ope…
Browse files Browse the repository at this point in the history
…n-telemetry#4267)

* docs: add observableGauge to the prometheus experimental example

Signed-off-by: Francois LP <[email protected]>

* docs: add gauge image to README

Signed-off-by: Francois LP <[email protected]>

* refactor: change comment wording

from @pichlermarc

Co-authored-by: Marc Pichler <[email protected]>

---------

Signed-off-by: Francois LP <[email protected]>
Co-authored-by: Marc Pichler <[email protected]>
Co-authored-by: Daniel Dyla <[email protected]>
  • Loading branch information
3 people authored and Zirak committed Sep 14, 2024
1 parent aec2ed1 commit f909cb7
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
1 change: 1 addition & 0 deletions experimental/examples/prometheus/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ If you are using the default configurations, the prometheus client will be avail

<p align="center"><img src="images/prom-counter.png?raw=true"/></p>
<p align="center"><img src="images/prom-updowncounter.png?raw=true"/></p>
<p align="center"><img src="images/prom-gauge.png?raw=true"/></p>

## Useful links

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 17 additions & 0 deletions experimental/examples/prometheus/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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++;
Expand Down

0 comments on commit f909cb7

Please sign in to comment.