public class Summary extends SimpleCollector<Summary.Child> implements Collector.Describable
Example of uses for Summaries include:
Example Summaries:
class YourClass {
static final Summary receivedBytes = Summary.build()
.name("requests_size_bytes").help("Request size in bytes.").register();
static final Summary requestLatency = Summary.build()
.name("requests_latency_seconds").help("Request latency in seconds.").register();
void processRequest(Request req) {
Summary.Timer requestTimer = requestLatency.startTimer();
try {
// Your code here.
} finally {
receivedBytes.observe(req.size());
requestTimer.observeDuration();
}
}
// Or if using Java 8 and lambdas.
void processRequestLambda(Request req) {
receivedBytes.observe(req.size());
requestLatency.time(() -> {
// Your code here.
});
}
}
This would allow you to track request rate, average latency and average request size.
How to add custom quantiles:
static final Summary myMetric = Summary.build()
.quantile(0.5, 0.05) // Add 50th percentile (= median) with 5% tolerated error
.quantile(0.9, 0.01) // Add 90th percentile with 1% tolerated error
.quantile(0.99, 0.001) // Add 99th percentile with 0.1% tolerated error
.name("requests_size_bytes")
.help("Request size in bytes.")
.register();
The quantiles are calculated over a sliding window of time. There are two options to configure this time window:
| Modifier and Type | Class and Description |
|---|---|
static class |
Summary.Builder |
static class |
Summary.Child
The value of a single Summary.
|
static class |
Summary.Timer
Represents an event being timed.
|
Collector.Describable, Collector.MetricFamilySamples, Collector.Typechildren, fullname, help, labelNames, noLabelsChildMILLISECONDS_PER_SECOND, NANOSECONDS_PER_SECOND| Modifier and Type | Method and Description |
|---|---|
static Summary.Builder |
build()
Return a Builder to allow configuration of a new Summary.
|
static Summary.Builder |
build(String name,
String help)
Return a Builder to allow configuration of a new Summary.
|
List<Collector.MetricFamilySamples> |
collect()
Return all of the metrics of this Collector.
|
List<Collector.MetricFamilySamples> |
describe()
Provide a list of metric families this Collector is expected to return.
|
Summary.Child.Value |
get()
Get the value of the Summary.
|
protected Summary.Child |
newChild()
Return a new child, workaround for Java generics limitations.
|
void |
observe(double amt)
Observe the given amount on the summary with no labels.
|
Summary.Timer |
startTimer()
Start a timer to track a duration on the summary with no labels.
|
<E> E |
time(Callable<E> timeable)
Executes callable code (e.g.
|
double |
time(Runnable timeable)
Executes runnable code (e.g.
|
clear, familySamplesList, initializeNoLabelsChild, labels, remove, setChildcheckMetricLabelName, checkMetricName, doubleToGoString, register, register, sanitizeMetricNamepublic static Summary.Builder build(String name, String help)
name - The name of the metrichelp - The help string of the metricpublic static Summary.Builder build()
protected Summary.Child newChild()
SimpleCollectornewChild in class SimpleCollector<Summary.Child>public void observe(double amt)
public Summary.Timer startTimer()
Call Summary.Timer.observeDuration() at the end of what you want to measure the duration of.
public double time(Runnable timeable)
timeable - Code that is being timedpublic <E> E time(Callable<E> timeable)
timeable - Code that is being timedpublic Summary.Child.Value get()
Warning: The definition of Summary.Child.Value is subject to change.
public List<Collector.MetricFamilySamples> collect()
Collectorpublic List<Collector.MetricFamilySamples> describe()
Collector.Describablecollect will be called at registration time instead of
describe. If this could cause problems, either implement a proper
describe, or if that's not practical have describe return an empty
list.describe in interface Collector.DescribableCopyright © 2019. All rights reserved.