1 | # hdr-histogram-percentiles-obj
|
---|
2 |
|
---|
3 | ## Install
|
---|
4 |
|
---|
5 | ```
|
---|
6 | npm install --save hdr-histogram-percentiles-obj
|
---|
7 | ```
|
---|
8 |
|
---|
9 | ## Usage
|
---|
10 |
|
---|
11 | ```js
|
---|
12 | const histPercentileObj = require('hdr-histogram-percentiles-obj')
|
---|
13 | const Histogram = require('hdr-histogram-js')
|
---|
14 |
|
---|
15 | const histogram = hdr.build({
|
---|
16 | lowestDiscernibleValue: 1,
|
---|
17 | highestTrackableValue: 100
|
---|
18 | })
|
---|
19 | const total = 0
|
---|
20 | // record some histogram data...
|
---|
21 | // total++...
|
---|
22 |
|
---|
23 | const result = histPercentileObj.histAsObj(histogram, total)
|
---|
24 | const resultWithPercentiles = histPercentileObj.addPercentiles(histogram, histPercentileObj.histAsObj(histogram, total))
|
---|
25 | histPercentileObj.percentiles.forEach((p) => {
|
---|
26 | const key = `p${p}`.replace('.', '_')
|
---|
27 | console.log(`${p}%`, resultWithPercentiles[key])
|
---|
28 | })
|
---|
29 | ```
|
---|
30 |
|
---|
31 | ## API
|
---|
32 |
|
---|
33 | hdr-histogram-percentiles-obj has two utility functions to use
|
---|
34 |
|
---|
35 | ### histAsObj(histogram, total)
|
---|
36 |
|
---|
37 | * `histogram`: A hdr-histogram-js object you want to get some values from in a js object
|
---|
38 | * `total`: the total amount recorded by the histogram, optional
|
---|
39 |
|
---|
40 | Returns a json object with the `min`, `max`, `average` (mean) and `stddev`
|
---|
41 |
|
---|
42 | ### addPercentiles(histogram, histAsObjResult)
|
---|
43 |
|
---|
44 | * `histogram`: A hdr-histogram-js object you want to retrieve the percentiles from
|
---|
45 | * `histAsObjResult`: the result returned when `histAsObj` is called on some hdr-histogram-js object
|
---|
46 |
|
---|
47 | Returns the histAsObjResult with the percentiles properties added. Percentile properties are named `pNN_DD`, for the `NN.DD%` percentile. Eg., the 99th percentile is `p99`, while the 99.99th percentile is `p99_99`.
|
---|
48 |
|
---|
49 | ### percentiles
|
---|
50 |
|
---|
51 | An array listing the percentiles that hdr-histogram-percentiles-obj adds, as numbers.
|
---|
52 |
|
---|
53 | ## Sponsor
|
---|
54 |
|
---|
55 | Kindly sponsored by [nearForm](www.nearform.com)
|
---|
56 |
|
---|
57 | ## License
|
---|
58 |
|
---|
59 | [MIT](./LICENSE)
|
---|