All Implemented Interfaces:
DataPoint, StateSetDataPoint, io.prometheus.metrics.model.registry.Collector

public class StateSet extends StatefulMetric<StateSetDataPoint,io.prometheus.metrics.core.metrics.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.
  • Method Details

    • collect

      public io.prometheus.metrics.model.snapshots.StateSetSnapshot collect()
      Specified by:
      collect in interface io.prometheus.metrics.model.registry.Collector
      Overrides:
      collect in class StatefulMetric<StateSetDataPoint,io.prometheus.metrics.core.metrics.StateSet.DataPoint>
    • collect

      protected io.prometheus.metrics.model.snapshots.StateSetSnapshot collect(List<io.prometheus.metrics.model.snapshots.Labels> labels, List<io.prometheus.metrics.core.metrics.StateSet.DataPoint> metricDataList)
      Description copied from class: StatefulMetric
      labels and metricData have the same size. labels.get(i) are the labels for metricData.get(i).
      Specified by:
      collect in class StatefulMetric<StateSetDataPoint,io.prometheus.metrics.core.metrics.StateSet.DataPoint>
    • getMetricType

      public io.prometheus.metrics.model.registry.MetricType getMetricType()
      Specified by:
      getMetricType in interface io.prometheus.metrics.model.registry.Collector
    • setTrue

      public void setTrue(String state)
      Description copied from interface: StateSetDataPoint
      state must be one of the states from when the StateSet was created with StateSet.Builder.states(String...).
      Specified by:
      setTrue in interface StateSetDataPoint
    • setFalse

      public void setFalse(String state)
      Description copied from interface: StateSetDataPoint
      state must be one of the states from when the StateSet was created with StateSet.Builder.states(String...).
      Specified by:
      setFalse in interface StateSetDataPoint
    • newDataPoint

      protected io.prometheus.metrics.core.metrics.StateSet.DataPoint newDataPoint()
      Specified by:
      newDataPoint in class StatefulMetric<StateSetDataPoint,io.prometheus.metrics.core.metrics.StateSet.DataPoint>
    • builder

      public static StateSet.Builder builder()
    • builder

      public static StateSet.Builder builder(io.prometheus.metrics.config.PrometheusProperties config)