stats.Histogram
Description
Histogram metric.
Histogram is one of a few types of metrics supported by the stats system. It keeps track of observations in an array of buckets, and can be used to calculate quantiles. Once you've created one, it becomes visible to the stats system, and its current value can be queried via admin port under the endpoint GET /metrics in Prometheus exposition formats.
You create a Histogram by a name and a series of bucket upper bounds, optionally providing label names if it has sub-metrics.
pipy({_lantency: new stats.Histogram('http_requests',new Array(16).fill(0).map((_, i) => Math.pow(2, i)),['service'],)})
Metric names starting with pipy_ are reserved for internal use.
After that, you collect observations by observe().
_lantency.observe(2.6)
You can also access a sub-metric by giving values to the labels. The label values must be given in the order they appear in the construction.
_lantency.withLabels('login-service').observe(3)
Constructor
new stats.Histogram(name, buckets, labelNames?)
Creates an instance of Histogram.
Methods
observe(n)
Increases the bucket where a sample falls in.
withLabels(...labels)
Retrieves a sub-metric by labels.
zero()
Clears all buckets.