Package io.prometheus.client
Class Enumeration
- java.lang.Object
-
- io.prometheus.client.Collector
-
- io.prometheus.client.SimpleCollector<Enumeration.Child>
-
- io.prometheus.client.Enumeration
-
- All Implemented Interfaces:
Collector.Describable
public class Enumeration extends SimpleCollector<Enumeration.Child> implements Collector.Describable
Enumeration metric, to track which of a set of states something is in. The first provided state will be the default.Example Enumeration:
You can also use a Java Enum:class YourClass { static final Enumeration taskState = Enumeration.build() .name("task_state").help("State of the task.") .states("stopped", "starting", "running") .register(); void stop() { // Your code here. taskState.state("stopped") } }class YourClass { public enum yourEnum { STOPPED, STARTING, RUNNING, } static final Enumeration taskState = Enumeration.build() .name("task_state").help("State of the task.") .states(yourEnum.class) .register(); void stop() { // Your code here. taskState.state(yourEnum.STOPPED) } } }- Since:
- 0.10.0
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classEnumeration.Builderstatic classEnumeration.ChildThe value of a single Enumeration.-
Nested classes/interfaces inherited from class io.prometheus.client.Collector
Collector.Describable, Collector.MetricFamilySamples, Collector.Type
-
-
Field Summary
-
Fields inherited from class io.prometheus.client.SimpleCollector
children, fullname, help, labelNames, noLabelsChild, unit
-
Fields inherited from class io.prometheus.client.Collector
MILLISECONDS_PER_SECOND, NANOSECONDS_PER_SECOND
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static Enumeration.Builderbuild()Return a Builder to allow configuration of a new Enumeration.static Enumeration.Builderbuild(String name, String help)Return a Builder to allow configuration of a new Enumeration.List<Collector.MetricFamilySamples>collect()Return all metrics of this Collector.List<Collector.MetricFamilySamples>describe()Provide a list of metric families this Collector is expected to return.Stringget()Get the value of the Enumeration.protected Enumeration.ChildnewChild()Return a new child, workaround for Java generics limitations.voidstate(Enum e)Set the state on the enum with no labels.voidstate(String s)Set the state on the enum with no labels.-
Methods inherited from class io.prometheus.client.SimpleCollector
clear, familySamplesList, initializeNoLabelsChild, labels, remove, setChild
-
Methods inherited from class io.prometheus.client.Collector
checkMetricLabelName, checkMetricName, collect, doubleToGoString, register, register, sanitizeMetricName
-
-
-
-
Method Detail
-
build
public static Enumeration.Builder build(String name, String help)
Return a Builder to allow configuration of a new Enumeration. Ensures required fields are provided.- Parameters:
name- The name of the metrichelp- The help string of the metric
-
build
public static Enumeration.Builder build()
Return a Builder to allow configuration of a new Enumeration.
-
newChild
protected Enumeration.Child newChild()
Description copied from class:SimpleCollectorReturn a new child, workaround for Java generics limitations.- Specified by:
newChildin classSimpleCollector<Enumeration.Child>
-
collect
public List<Collector.MetricFamilySamples> collect()
Description copied from class:CollectorReturn all metrics of this Collector.
-
describe
public List<Collector.MetricFamilySamples> describe()
Description copied from interface:Collector.DescribableProvide a list of metric families this Collector is expected to return. These should exclude the samples. This is used by the registry to detect collisions and duplicate registrations. Usually custom collectors do not have to implement Describable. If Describable is not implemented and the CollectorRegistry was created with auto describe enabled (which is the case for the default registry) thenCollector.collect()will be called at registration time instead of describe. If this could cause problems, either implement a proper describe, or if that's not practical have describe return an empty list.- Specified by:
describein interfaceCollector.Describable
-
-