public class Histogram extends SimpleCollector<Histogram.Child,Histogram>
Example of uses for Histograms include:
Note: Each bucket is one timeseries. Many buckets and/or many dimensions with labels can produce large amount of time series, that may cause performance problems.
The default buckets are intended to cover a typical web/rpc request from milliseconds to seconds.
Example Histograms:
class YourClass {
static final Histogram requestLatency = Histogram.build()
.name("requests_latency_seconds").help("Request latency in seconds.").register();
void processRequest(Request req) {
Histogram.Timer requestTimer = requestLatency.startTimer();
try {
// Your code here.
} finally {
requestTimer.observeDuration();
}
}
}
You can choose your own buckets:
static final Histogram requestLatency = Histogram.build()
.buckets(.01, .02, .03, .04)
.name("requests_latency_seconds").help("Request latency in seconds.").register();
linearBuckets
and
exponentialBuckets
offer easy ways to set common bucket patterns.Modifier and Type | Class and Description |
---|---|
static class |
Histogram.Builder |
static class |
Histogram.Child
The value of a single Histogram.
|
static class |
Histogram.Timer
Represents an event being timed.
|
Collector.MetricFamilySamples, Collector.Type
children, fullname, help, labelNames, noLabelsChild
METRIC_LABEL_NAME_RE, METRIC_NAME_RE, MILLISECONDS_PER_SECOND, NANOSECONDS_PER_SECOND, RESERVED_METRIC_LABEL_NAME_RE
Modifier and Type | Method and Description |
---|---|
static Histogram.Builder |
build()
Return a Builder to allow configuration of a new Histogram.
|
List<Collector.MetricFamilySamples> |
collect()
Return all of the metrics of this Collector.
|
protected Histogram.Child |
newChild()
Return a new child, workaround for Java generics limitations.
|
void |
observe(double amt)
Observe the given amount on the histogram with no labels.
|
Histogram.Timer |
startTimer()
Start a timer to track a duration on the histogram with no labels.
|
clear, initializeNoLabelsChild, labels, remove, setChild
checkMetricLabelName, checkMetricName, doubleToGoString, register, register
public static Histogram.Builder build()
protected Histogram.Child newChild()
SimpleCollector
newChild
in class SimpleCollector<Histogram.Child,Histogram>
public void observe(double amt)
public Histogram.Timer startTimer()
Call Histogram.Timer.observeDuration()
at the end of what you want to measure the duration of.
public List<Collector.MetricFamilySamples> collect()
Collector
Copyright © 2015. All rights reserved.