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