MCPcopy
hub / github.com/prometheus/client_js / main

Function main

example/counter.js:9–73  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

7const { Counter, register } = require('..');
8
9async 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());

Callers 1

counter.jsFile · 0.70

Calls 4

resetMethod · 0.95
labelsMethod · 0.95
metricsMethod · 0.80
incMethod · 0.65

Tested by

no test coverage detected