Class StateSet
- All Implemented Interfaces:
DataPoint, StateSetDataPoint, Collector
public class StateSet
extends StatefulMetric<StateSetDataPoint, StateSet.DataPoint>
implements StateSetDataPoint
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) collect()Called when the Prometheus server scrapes metrics.Returns the metric type for registration-time validation.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 StatefulMetric
clear, initLabelValues, labelValues, remove, removeIfMethods inherited from class MetricWithFixedMetadata
getLabelNames, getMetadata, getPrometheusNameMethods inherited from class Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface StateSetDataPoint
setFalse, setTrue
-
Method Details
-
collect
Description copied from interface:CollectorCalled when the Prometheus server scrapes metrics.- Specified by:
collectin interfaceCollector- Overrides:
collectin classStatefulMetric<StateSetDataPoint, StateSet.DataPoint>
-
getMetricType
Description copied from interface:CollectorReturns the metric type for registration-time validation.This is used to prevent different metric types (e.g., Counter and Gauge) from sharing the same name. Returning
nullmeans type validation is skipped for this collector.Validation is performed only at registration time. If this method returns
null, no type validation is performed for this collector, and duplicate or conflicting metrics may result in invalid exposition output.- Specified by:
getMetricTypein interfaceCollector- Returns:
- the metric type, or
nullto skip validation
-
setTrue
Description copied from interface:StateSetDataPointstatemust be one of the states from when theStateSetwas created withStateSet.Builder.states(String...).- Specified by:
setTruein interfaceStateSetDataPoint
-
setFalse
Description copied from interface:StateSetDataPointstatemust be one of the states from when theStateSetwas created withStateSet.Builder.states(String...).- Specified by:
setFalsein interfaceStateSetDataPoint
-
builder
-
builder
-