Skip to content

Commit

Permalink
docs: add observableGauge to the prometheus experimental example (#4267)
Browse files Browse the repository at this point in the history
* docs: add observableGauge to the prometheus experimental example

Signed-off-by: Francois LP <francois.le.pape@gmail.com>

* docs: add gauge image to README

Signed-off-by: Francois LP <francois.le.pape@gmail.com>

* refactor: change comment wording

from @pichlermarc

Co-authored-by: Marc Pichler <marc.pichler@dynatrace.com>

---------

Signed-off-by: Francois LP <francois.le.pape@gmail.com>
Co-authored-by: Marc Pichler <marc.pichler@dynatrace.com>
Co-authored-by: Daniel Dyla <dyladan@users.noreply.github.com>
  • Loading branch information
3 people committed Jan 25, 2024
1 parent bf4d553 commit 5afbcdb
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 5afbcdb

Please sign in to comment.