Skip to content

Commit

Permalink
docs: add missing awaits/thens to examples
Browse files Browse the repository at this point in the history
  • Loading branch information
zbjornson committed Sep 19, 2021
1 parent c9bf1d8 commit 074f339
Show file tree
Hide file tree
Showing 7 changed files with 126 additions and 123 deletions.
136 changes: 67 additions & 69 deletions example/counter.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,73 +5,71 @@
// Multiple Values

const { Counter, register } = require('..');
const c = new Counter({
name: 'test_counter',
help: 'Example of a counter',
labelNames: ['code'],
});

c.inc({ code: 200 });
console.log(register.metrics());

/*
# HELP test_counter Example of a counter
# TYPE test_counter counter
test_counter{code="200"} 1
*/

c.inc({ code: 200 });
console.log(register.metrics());

/*
# HELP test_counter Example of a counter
# TYPE test_counter counter
test_counter{code="200"} 2
*/

c.inc();
console.log(register.metrics());

/*
# HELP test_counter Example of a counter
# TYPE test_counter counter
test_counter{code="200"} 2
test_counter 1
*/

c.reset();
console.log(register.metrics());

/*
# HELP test_counter Example of a counter
# TYPE test_counter counter
*/

c.inc(15);
console.log(register.metrics());

/*
# HELP test_counter Example of a counter
# TYPE test_counter counter
test_counter 15
*/

c.inc({ code: 200 }, 12);
console.log(register.metrics());

/*
# HELP test_counter Example of a counter
# TYPE test_counter counter
test_counter 15
test_counter{code="200"} 12
*/

c.labels('200').inc(12);
console.log(register.metrics());

/*
# HELP test_counter Example of a counter
# TYPE test_counter counter
test_counter 15
test_counter{code="200"} 24
*/
async function main() {
const c = new Counter({
name: 'test_counter',
help: 'Example of a counter',
labelNames: ['code'],
});

c.inc({ code: 200 });
console.log(await register.metrics());
/*
# HELP test_counter Example of a counter
# TYPE test_counter counter
test_counter{code="200"} 1
*/

c.inc({ code: 200 });
console.log(await register.metrics());
/*
# HELP test_counter Example of a counter
# TYPE test_counter counter
test_counter{code="200"} 2
*/

c.inc();
console.log(await register.metrics());
/*
# HELP test_counter Example of a counter
# TYPE test_counter counter
test_counter{code="200"} 2
test_counter 1
*/

c.reset();
console.log(await register.metrics());
/*
# HELP test_counter Example of a counter
# TYPE test_counter counter
*/

c.inc(15);
console.log(await register.metrics());
/*
# HELP test_counter Example of a counter
# TYPE test_counter counter
test_counter 15
*/

c.inc({ code: 200 }, 12);
console.log(await register.metrics());
/*
# HELP test_counter Example of a counter
# TYPE test_counter counter
test_counter 15
test_counter{code="200"} 12
*/

c.labels('200').inc(12);
console.log(await register.metrics());
/*
# HELP test_counter Example of a counter
# TYPE test_counter counter
test_counter 15
test_counter{code="200"} 24
*/
}

main();
2 changes: 1 addition & 1 deletion example/default-metrics.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ collectDefaultMetrics({
gcDurationBuckets: [0.001, 0.01, 0.1, 1, 2, 5], // These are the default buckets.
});

console.log(register.metrics());
register.metrics().then(str => console.log(str));

/*
Output from metrics():
Expand Down
103 changes: 54 additions & 49 deletions example/gauge.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,52 +5,57 @@
// Multiple Values

const { Gauge, register } = require('..');
const g = new Gauge({
name: 'test_gauge',
help: 'Example of a gauge',
labelNames: ['code'],
});

g.set({ code: 200 }, 5);
console.log(register.metrics());
/*
# HELP test_gauge Example of a gauge
# TYPE test_gauge gauge
test_gauge{code="200"} 5
*/

g.set(15);
console.log(register.metrics());
/*
# HELP test_gauge Example of a gauge
# TYPE test_gauge gauge
test_gauge{code="200"} 5
test_gauge 15
*/

g.labels('200').inc();
console.log(register.metrics());
/*
# HELP test_gauge Example of a gauge
# TYPE test_gauge gauge
test_gauge{code="200"} 6
test_gauge 15
*/

g.inc();
console.log(register.metrics());
/*
# HELP test_gauge Example of a gauge
# TYPE test_gauge gauge
test_gauge{code="200"} 6
test_gauge 16
*/

g.set(22);
console.log(register.metrics());
/*
# HELP test_gauge Example of a gauge
# TYPE test_gauge gauge
test_gauge{code="200"} 6
test_gauge 22
*/

async function main() {
const g = new Gauge({
name: 'test_gauge',
help: 'Example of a gauge',
labelNames: ['code'],
});

g.set({ code: 200 }, 5);
console.log(await register.metrics());
/*
# HELP test_gauge Example of a gauge
# TYPE test_gauge gauge
test_gauge{code="200"} 5
*/

g.set(15);
console.log(await register.metrics());
/*
# HELP test_gauge Example of a gauge
# TYPE test_gauge gauge
test_gauge{code="200"} 5
test_gauge 15
*/

g.labels('200').inc();
console.log(await register.metrics());
/*
# HELP test_gauge Example of a gauge
# TYPE test_gauge gauge
test_gauge{code="200"} 6
test_gauge 15
*/

g.inc();
console.log(await register.metrics());
/*
# HELP test_gauge Example of a gauge
# TYPE test_gauge gauge
test_gauge{code="200"} 6
test_gauge 16
*/

g.set(22);
console.log(await register.metrics());
/*
# HELP test_gauge Example of a gauge
# TYPE test_gauge gauge
test_gauge{code="200"} 6
test_gauge 22
*/
}

main();
2 changes: 1 addition & 1 deletion example/histogram-1.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ h.labels('200').observe(0.6);

h.observe({ code: '200' }, 0.4);

console.log(register.metrics());
register.metrics().then(str => console.log(str));

/*
Output from metrics():
Expand Down
2 changes: 1 addition & 1 deletion example/histogram-2.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ h.labels('300').observe(0.6);

h.observe({ code: '200' }, 0.4);

console.log(register.metrics());
register.metrics().then(str => console.log(str));

/*
Output from metrics():
Expand Down
2 changes: 1 addition & 1 deletion example/histogram-3.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ h.labels('200', 'blue').observe(0.6);

h.observe({ code: '200', color: 'blue' }, 0.4);

console.log(register.metrics());
register.metrics().then(str => console.log(str));

/*
Output from metrics():
Expand Down
2 changes: 1 addition & 1 deletion example/histogram-4.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ h.labels('300', 'red').observe(0.6);
h.labels('300', 'blue').observe(0.4);
h.labels('200', 'red').observe(0.6);

console.log(register.metrics());
register.metrics().then(str => console.log(str));

/*
Output from metrics():
Expand Down

0 comments on commit 074f339

Please sign in to comment.