public class Gauge extends SimpleCollector<Gauge.Child>
Examples of Gauges include:
An example Gauge:
class YourClass {
static final Gauge inprogressRequests = Gauge.build()
.name("inprogress_requests").help("Inprogress requests.").register();
void processRequest() {
inprogressRequest.inc();
// Your code here.
inprogressRequest.dec();
}
}
You can also use labels to track different types of metric:
class YourClass {
static final Gauge inprogressRequests = Gauge.build()
.name("inprogress_requests").help("Inprogress requests.")
.labelNames("method").register();
void processGetRequest() {
inprogressRequests.labels("get").inc();
// Your code here.
inprogressRequests.labels("get").dec();
}
void processPostRequest() {
inprogressRequests.labels("post").inc();
// Your code here.
inprogressRequests.labels("post").dec();
}
}
These can be aggregated and processed together much more easily in the Prometheus server than individual metrics for each labelset.
Modifier and Type | Class and Description |
---|---|
static class |
Gauge.Builder |
static class |
Gauge.Child
The value of a single Gauge.
|
static class |
Gauge.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 Gauge.Builder |
build()
Return a Builder to allow configuration of a new Gauge.
|
List<Collector.MetricFamilySamples> |
collect()
Return all of the metrics of this Collector.
|
void |
dec()
Increment the gauge with no labels by 1.
|
void |
dec(double amt)
Decrement the gauge with no labels by the given amount.
|
void |
inc()
Increment the gauge with no labels by 1.
|
void |
inc(double amt)
Increment the gauge with no labels by the given amount.
|
protected Gauge.Child |
newChild()
Return a new child, workaround for Java generics limitations.
|
void |
set(double val)
Set the gauge with no labels to the given value.
|
void |
setToCurrentTime()
Set the gauge with no labels to the current unixtime.
|
Gauge.Timer |
startTimer()
Start a timer to track a duration, for the gauge with no labels.
|
clear, initializeNoLabelsChild, labels, remove, setChild
checkMetricLabelName, checkMetricName, doubleToGoString, register, register
public static Gauge.Builder build()
protected Gauge.Child newChild()
SimpleCollector
newChild
in class SimpleCollector<Gauge.Child>
public void inc()
public void inc(double amt)
public void dec()
public void dec(double amt)
public void set(double val)
public void setToCurrentTime()
public Gauge.Timer startTimer()
This is primarily useful for tracking the durations of major steps of batch jobs,
which are then pushed to a PushGateway.
For tracking other durations/latencies you should usually use a Summary
.
Call Gauge.Timer.setDuration()
at the end of what you want to measure the duration of.
Copyright © 2016. All rights reserved.