Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: update metrics example with UpDownCounter #1239

Merged
merged 7 commits into from
Jun 28, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
chore: update metrics example with UpDownCounter
mayurkale22 committed Jun 24, 2020
commit 7feafc375e99c2851d2a94a04e94dae296047d87
3 changes: 2 additions & 1 deletion examples/prometheus/README.md
Original file line number Diff line number Diff line change
@@ -48,7 +48,8 @@ prometheus --config.file=prometheus.yml

If you are using the default configurations, the prometheus client will be available at <http://localhost:9090>

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

## Useful links

Binary file added examples/prometheus/images/prom-counter.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed examples/prometheus/images/prom-ui.png
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 7 additions & 11 deletions examples/prometheus/index.js
Original file line number Diff line number Diff line change
@@ -19,21 +19,17 @@ const meter = new MeterProvider({
interval: 1000,
}).getMeter('example-prometheus');

// Monotonic counters can only be increased.
const monotonicCounter = meter.createCounter('monotonic_counter', {
monotonic: true,
description: 'Example of a monotonic counter',
const requestCounter = meter.createCounter('requests', {
description: 'Example of a Counter',
});

// Non-monotonic counters can be increased or decreased.
const nonMonotonicCounter = meter.createCounter('non_monotonic_counter', {
monotonic: false,
description: 'Example of a non-monotonic counter',
const upDownCounter = meter.createUpDownCounter('test_up_down_counter', {
description: 'Example of a UpDownCounter',
});

const labels = { pid: process.pid };
const labels = { pid: process.pid, environment: 'staging' };

setInterval(() => {
monotonicCounter.bind(labels).add(1);
nonMonotonicCounter.bind(labels).add(Math.random() > 0.5 ? 1 : -1);
requestCounter.bind(labels).add(1);
upDownCounter.bind(labels).add(Math.random() > 0.5 ? 1 : -1);
}, 1000);