Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ project adheres to [Semantic Versioning](http://semver.org/).

- Expanded benchmarking code
- new WorkerRegistry to provide equivalent support to AggregatorRegistry
- Added example for Summary metric

## [15.1.3] - 2024-06-27

Expand Down
66 changes: 66 additions & 0 deletions example/summary.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
'use strict';

// Summary
// Single Label
// Multiple Values

const { Summary, register } = require('..');

async function main() {
const summ = new Summary({
name: 'test_summary',
help: 'Example of summary',
labelNames: ['code'],
percentiles: [0.5, 0.9, 0.99],
});

summ.observe({ code: '200' }, 0.7);
summ.observe({ code: '200' }, 0.1);
summ.observe({ code: '400' }, 1.5);
summ.observe({ code: '500' }, 2.2);

console.log(await register.metrics());
/*
# HELP test_summary Example of summary
# TYPE test_summary summary
test_summary{quantile="0.5",code="200"} 0.4
test_summary{quantile="0.9",code="200"} 0.7
test_summary{quantile="0.99",code="200"} 0.7
test_summary_sum{code="200"} 0.7999999999999999
test_summary_count{code="200"} 2
test_summary{quantile="0.5",code="400"} 1.5
test_summary{quantile="0.9",code="400"} 1.5
test_summary{quantile="0.99",code="400"} 1.5
test_summary_sum{code="400"} 1.5
test_summary_count{code="400"} 1
test_summary{quantile="0.5",code="500"} 2.2
test_summary{quantile="0.9",code="500"} 2.2
test_summary{quantile="0.99",code="500"} 2.2
test_summary_sum{code="500"} 2.2
test_summary_count{code="500"} 1
*/

summ.observe({ code: '200' }, 0.4);
console.log(await register.metrics());
/*
# HELP test_summary Example of summary
# TYPE test_summary summary
test_summary{quantile="0.5",code="200"} 0.4
test_summary{quantile="0.9",code="200"} 0.7
test_summary{quantile="0.99",code="200"} 0.7
test_summary_sum{code="200"} 1.2
test_summary_count{code="200"} 3
test_summary{quantile="0.5",code="400"} 1.5
test_summary{quantile="0.9",code="400"} 1.5
test_summary{quantile="0.99",code="400"} 1.5
test_summary_sum{code="400"} 1.5
test_summary_count{code="400"} 1
test_summary{quantile="0.5",code="500"} 2.2
test_summary{quantile="0.9",code="500"} 2.2
test_summary{quantile="0.99",code="500"} 2.2
test_summary_sum{code="500"} 2.2
test_summary_count{code="500"} 1
*/
}

main();