Skip to content

Commit 074f339

Browse files
committed
docs: add missing awaits/thens to examples
1 parent c9bf1d8 commit 074f339

File tree

7 files changed

+126
-123
lines changed

7 files changed

+126
-123
lines changed

example/counter.js

Lines changed: 67 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -5,73 +5,71 @@
55
// Multiple Values
66

77
const { Counter, register } = require('..');
8-
const c = new Counter({
9-
name: 'test_counter',
10-
help: 'Example of a counter',
11-
labelNames: ['code'],
12-
});
138

14-
c.inc({ code: 200 });
15-
console.log(register.metrics());
16-
17-
/*
18-
# HELP test_counter Example of a counter
19-
# TYPE test_counter counter
20-
test_counter{code="200"} 1
21-
*/
22-
23-
c.inc({ code: 200 });
24-
console.log(register.metrics());
25-
26-
/*
27-
# HELP test_counter Example of a counter
28-
# TYPE test_counter counter
29-
test_counter{code="200"} 2
30-
*/
31-
32-
c.inc();
33-
console.log(register.metrics());
34-
35-
/*
36-
# HELP test_counter Example of a counter
37-
# TYPE test_counter counter
38-
test_counter{code="200"} 2
39-
test_counter 1
40-
*/
41-
42-
c.reset();
43-
console.log(register.metrics());
44-
45-
/*
46-
# HELP test_counter Example of a counter
47-
# TYPE test_counter counter
48-
*/
49-
50-
c.inc(15);
51-
console.log(register.metrics());
52-
53-
/*
54-
# HELP test_counter Example of a counter
55-
# TYPE test_counter counter
56-
test_counter 15
57-
*/
58-
59-
c.inc({ code: 200 }, 12);
60-
console.log(register.metrics());
61-
62-
/*
63-
# HELP test_counter Example of a counter
64-
# TYPE test_counter counter
65-
test_counter 15
66-
test_counter{code="200"} 12
67-
*/
68-
69-
c.labels('200').inc(12);
70-
console.log(register.metrics());
71-
72-
/*
73-
# HELP test_counter Example of a counter
74-
# TYPE test_counter counter
75-
test_counter 15
76-
test_counter{code="200"} 24
77-
*/
9+
async function main() {
10+
const c = new Counter({
11+
name: 'test_counter',
12+
help: 'Example of a counter',
13+
labelNames: ['code'],
14+
});
15+
16+
c.inc({ code: 200 });
17+
console.log(await register.metrics());
18+
/*
19+
# HELP test_counter Example of a counter
20+
# TYPE test_counter counter
21+
test_counter{code="200"} 1
22+
*/
23+
24+
c.inc({ code: 200 });
25+
console.log(await register.metrics());
26+
/*
27+
# HELP test_counter Example of a counter
28+
# TYPE test_counter counter
29+
test_counter{code="200"} 2
30+
*/
31+
32+
c.inc();
33+
console.log(await register.metrics());
34+
/*
35+
# HELP test_counter Example of a counter
36+
# TYPE test_counter counter
37+
test_counter{code="200"} 2
38+
test_counter 1
39+
*/
40+
41+
c.reset();
42+
console.log(await register.metrics());
43+
/*
44+
# HELP test_counter Example of a counter
45+
# TYPE test_counter counter
46+
*/
47+
48+
c.inc(15);
49+
console.log(await register.metrics());
50+
/*
51+
# HELP test_counter Example of a counter
52+
# TYPE test_counter counter
53+
test_counter 15
54+
*/
55+
56+
c.inc({ code: 200 }, 12);
57+
console.log(await register.metrics());
58+
/*
59+
# HELP test_counter Example of a counter
60+
# TYPE test_counter counter
61+
test_counter 15
62+
test_counter{code="200"} 12
63+
*/
64+
65+
c.labels('200').inc(12);
66+
console.log(await register.metrics());
67+
/*
68+
# HELP test_counter Example of a counter
69+
# TYPE test_counter counter
70+
test_counter 15
71+
test_counter{code="200"} 24
72+
*/
73+
}
74+
75+
main();

example/default-metrics.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ collectDefaultMetrics({
77
gcDurationBuckets: [0.001, 0.01, 0.1, 1, 2, 5], // These are the default buckets.
88
});
99

10-
console.log(register.metrics());
10+
register.metrics().then(str => console.log(str));
1111

1212
/*
1313
Output from metrics():

example/gauge.js

Lines changed: 54 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -5,52 +5,57 @@
55
// Multiple Values
66

77
const { Gauge, register } = require('..');
8-
const g = new Gauge({
9-
name: 'test_gauge',
10-
help: 'Example of a gauge',
11-
labelNames: ['code'],
12-
});
13-
14-
g.set({ code: 200 }, 5);
15-
console.log(register.metrics());
16-
/*
17-
# HELP test_gauge Example of a gauge
18-
# TYPE test_gauge gauge
19-
test_gauge{code="200"} 5
20-
*/
21-
22-
g.set(15);
23-
console.log(register.metrics());
24-
/*
25-
# HELP test_gauge Example of a gauge
26-
# TYPE test_gauge gauge
27-
test_gauge{code="200"} 5
28-
test_gauge 15
29-
*/
30-
31-
g.labels('200').inc();
32-
console.log(register.metrics());
33-
/*
34-
# HELP test_gauge Example of a gauge
35-
# TYPE test_gauge gauge
36-
test_gauge{code="200"} 6
37-
test_gauge 15
38-
*/
39-
40-
g.inc();
41-
console.log(register.metrics());
42-
/*
43-
# HELP test_gauge Example of a gauge
44-
# TYPE test_gauge gauge
45-
test_gauge{code="200"} 6
46-
test_gauge 16
47-
*/
48-
49-
g.set(22);
50-
console.log(register.metrics());
51-
/*
52-
# HELP test_gauge Example of a gauge
53-
# TYPE test_gauge gauge
54-
test_gauge{code="200"} 6
55-
test_gauge 22
56-
*/
8+
9+
async function main() {
10+
const g = new Gauge({
11+
name: 'test_gauge',
12+
help: 'Example of a gauge',
13+
labelNames: ['code'],
14+
});
15+
16+
g.set({ code: 200 }, 5);
17+
console.log(await register.metrics());
18+
/*
19+
# HELP test_gauge Example of a gauge
20+
# TYPE test_gauge gauge
21+
test_gauge{code="200"} 5
22+
*/
23+
24+
g.set(15);
25+
console.log(await register.metrics());
26+
/*
27+
# HELP test_gauge Example of a gauge
28+
# TYPE test_gauge gauge
29+
test_gauge{code="200"} 5
30+
test_gauge 15
31+
*/
32+
33+
g.labels('200').inc();
34+
console.log(await register.metrics());
35+
/*
36+
# HELP test_gauge Example of a gauge
37+
# TYPE test_gauge gauge
38+
test_gauge{code="200"} 6
39+
test_gauge 15
40+
*/
41+
42+
g.inc();
43+
console.log(await register.metrics());
44+
/*
45+
# HELP test_gauge Example of a gauge
46+
# TYPE test_gauge gauge
47+
test_gauge{code="200"} 6
48+
test_gauge 16
49+
*/
50+
51+
g.set(22);
52+
console.log(await register.metrics());
53+
/*
54+
# HELP test_gauge Example of a gauge
55+
# TYPE test_gauge gauge
56+
test_gauge{code="200"} 6
57+
test_gauge 22
58+
*/
59+
}
60+
61+
main();

example/histogram-1.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ h.labels('200').observe(0.6);
1717

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

20-
console.log(register.metrics());
20+
register.metrics().then(str => console.log(str));
2121

2222
/*
2323
Output from metrics():

example/histogram-2.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ h.labels('300').observe(0.6);
1717

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

20-
console.log(register.metrics());
20+
register.metrics().then(str => console.log(str));
2121

2222
/*
2323
Output from metrics():

example/histogram-3.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ h.labels('200', 'blue').observe(0.6);
1717

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

20-
console.log(register.metrics());
20+
register.metrics().then(str => console.log(str));
2121

2222
/*
2323
Output from metrics():

example/histogram-4.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ h.labels('300', 'red').observe(0.6);
1717
h.labels('300', 'blue').observe(0.4);
1818
h.labels('200', 'red').observe(0.6);
1919

20-
console.log(register.metrics());
20+
register.metrics().then(str => console.log(str));
2121

2222
/*
2323
Output from metrics():

0 commit comments

Comments
 (0)