Class StateSet
java.lang.Object
io.prometheus.metrics.core.metrics.Metric
io.prometheus.metrics.core.metrics.MetricWithFixedMetadata
io.prometheus.metrics.core.metrics.StatefulMetric<StateSetDataPoint,StateSet.DataPoint>
io.prometheus.metrics.core.metrics.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 ClassesModifier and TypeClassDescriptionstatic class(package private) class -
Field Summary
FieldsFields inherited from class io.prometheus.metrics.core.metrics.MetricWithFixedMetadata
labelNamesFields inherited from class io.prometheus.metrics.core.metrics.Metric
constLabels -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic StateSet.Builderbuilder()static StateSet.Builderbuilder(PrometheusProperties config) collect()Called when the Prometheus server scrapes metrics.protected StateSetSnapshotcollect(List<Labels> labels, List<StateSet.DataPoint> metricDataList) labels and metricData have the same size.Returns the metric type for registration-time validation.protected StateSet.DataPointvoidstatemust 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 io.prometheus.metrics.core.metrics.StatefulMetric
clear, getConfigProperty, getMetricProperties, getNoLabels, initLabelValues, labelValues, remove, removeIfMethods inherited from class io.prometheus.metrics.core.metrics.MetricWithFixedMetadata
getLabelNames, getMetadata, getPrometheusNameMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface io.prometheus.metrics.model.registry.Collector
collect, collect, collectMethods inherited from interface io.prometheus.metrics.core.datapoints.StateSetDataPoint
setFalse, setTrue
-
Field Details
-
names
-
-
Constructor Details
-
StateSet
-
-
Method Details
-
collect
Description copied from interface:CollectorCalled when the Prometheus server scrapes metrics.- Specified by:
collectin interfaceCollector- Overrides:
collectin classStatefulMetric<StateSetDataPoint,StateSet.DataPoint>
-
collect
Description copied from class:StatefulMetriclabels and metricData have the same size. labels.get(i) are the labels for metricData.get(i).- Specified by:
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
-
newDataPoint
- Specified by:
newDataPointin classStatefulMetric<StateSetDataPoint,StateSet.DataPoint>
-
builder
-
builder
-