public class Gauge extends SimpleCollector<Gauge.Child,Gauge>
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.Typechildren, fullname, help, labelNames, noLabelsChildMETRIC_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, setChildcheckMetricLabelName, checkMetricName, doubleToGoString, register, registerpublic static Gauge.Builder build()
protected Gauge.Child newChild()
SimpleCollectornewChild in class SimpleCollector<Gauge.Child,Gauge>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 with 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.
public List<Collector.MetricFamilySamples> collect()
CollectorCopyright © 2015. All rights reserved.