Skip to content

Commit 5afbcdb

Browse files
Lp-Francoispichlermarcdyladan
authored
docs: add observableGauge to the prometheus experimental example (#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]>
1 parent bf4d553 commit 5afbcdb

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-0
lines changed

experimental/examples/prometheus/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ If you are using the default configurations, the prometheus client will be avail
6060

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

6465
## Useful links
6566

339 KB
Loading

experimental/examples/prometheus/index.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,23 @@ observableCounter.addCallback(observableResult => {
3939
observableResult.observe(counter, attributes);
4040
});
4141

42+
const randomMetricPromise = async () =>
43+
new Promise(resolve =>
44+
setTimeout(resolve(Math.floor(Math.random() * 100)), 50)
45+
);
46+
47+
const observableGauge = meter.createObservableGauge(
48+
'observable_gauge_requests',
49+
{
50+
description: 'Example of an ObservableGauge',
51+
}
52+
);
53+
// Callbacks are run when metrics are scraped
54+
observableGauge.addCallback(async observableResult => {
55+
const value = await randomMetricPromise();
56+
observableResult.observe(value, attributes);
57+
});
58+
4259
// Record metrics
4360
setInterval(() => {
4461
counter++;

0 commit comments

Comments
 (0)