Object
Metric
MetricWithFixedMetadata
StateSet
- All Implemented Interfaces:
DataPoint,StateSetDataPoint,Collector
StateSet metric. Example:
public enum Feature {
FEATURE_1("feature1"),
FEATURE_2("feature2");
private final String name;
Feature(String name) {
this.name = name;
}
// Override
public String toString() {
return name;
}
}
public static void main(String[] args) {
StateSet stateSet = StateSet.builder()
.name("feature_flags")
.help("Feature flags")
.labelNames("env")
.states(Feature.class)
.register();
stateSet.labelValues("dev").setFalse(FEATURE_1);
stateSet.labelValues("dev").setTrue(FEATURE_2);
}
The example above shows how to use a StateSet with an enum.
You don't have to use enum, you can use regular strings as well.-
Nested Class Summary
Nested Classes -
Method Summary
Modifier and TypeMethodDescriptionstatic StateSet.Builderbuilder()static StateSet.Builderbuilder(PrometheusProperties config) voidclear()Reset the metric (remove all data points).StateSetSnapshotcollect()voidinitLabelValues(String... labelValues) Initialize label values.labelValues(String... labelValues) voidRemove the data point with the given label values.voidstatemust be one of the states from when theStateSetwas created withStateSet.Builder.states(String...).voidstatemust be one of the states from when theStateSetwas created withStateSet.Builder.states(String...).Methods inherited from class MetricWithFixedMetadata
getPrometheusNameMethods inherited from class Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface Collector
collect, collect, collectMethods inherited from interface StateSetDataPoint
setFalse, setTrue
-
Method Details
-
collect
- Specified by:
collectin interfaceCollector
-
setTrue
statemust be one of the states from when theStateSetwas created withStateSet.Builder.states(String...).- Specified by:
setTruein interfaceStateSetDataPoint
-
setFalse
statemust be one of the states from when theStateSetwas created withStateSet.Builder.states(String...).- Specified by:
setFalsein interfaceStateSetDataPoint
-
builder
-
builder
-
initLabelValues
Initialize label values.Example: Imagine you have a counter for payments as follows
payment_transactions_total{payment_type="credit card"} 7.0 payment_transactions_total{payment_type="paypal"} 3.0Now, the data points for thepayment_typelabel values get initialized when they are first used, i.e. the first time you call
the data point with labelcounter.labelValues("paypal").inc();payment_type="paypal"will go from non-existent to having value1.0.In some cases this is confusing, and you want to have data points initialized on application start with an initial value of
0.0:payment_transactions_total{payment_type="credit card"} 0.0 payment_transactions_total{payment_type="paypal"} 0.0initLabelValues(...)can be used to initialize label value, so that the data points show up in the exposition format with an initial value of zero. -
labelValues
-
remove
Remove the data point with the given label values. See https://prometheus.io/docs/instrumenting/writing_clientlibs/#labels. -
clear
public void clear()Reset the metric (remove all data points).
-