Class Exemplar

java.lang.Object
io.prometheus.client.exemplars.Exemplar

public class Exemplar extends Object
Immutable data class holding an Exemplar.
  • Field Details

    • labels

      private final String[] labels
    • value

      private final double value
    • timestampMs

      private final Long timestampMs
    • labelNameRegex

      private static final Pattern labelNameRegex
  • Constructor Details

    • Exemplar

      public Exemplar(double value, String... labels)
      Create an Exemplar without a timestamp
      Parameters:
      value - the observed value
      labels - name/value pairs. Expecting an even number of strings. The combined length of the label names and values must not exceed 128 UTF-8 characters. Neither a label name nor a label value may be null.
    • Exemplar

      public Exemplar(double value, Long timestampMs, String... labels)
      Create an Exemplar
      Parameters:
      value - the observed value
      timestampMs - as in System.currentTimeMillis()
      labels - name/value pairs. Expecting an even number of strings. The combined length of the label names and values must not exceed 128 UTF-8 characters. Neither a label name nor a label value may be null.
    • Exemplar

      public Exemplar(double value, Map<String,String> labels)
      Create an Exemplar
      Parameters:
      value - the observed value
      labels - the labels. Must not be null. The combined length of the label names and values must not exceed 128 UTF-8 characters. Neither a label name nor a label value may be null.
    • Exemplar

      public Exemplar(double value, Long timestampMs, Map<String,String> labels)
      Create an Exemplar
      Parameters:
      value - the observed value
      timestampMs - as in System.currentTimeMillis()
      labels - the labels. Must not be null. The combined length of the label names and values must not exceed 128 UTF-8 characters. Neither a label name nor a label value may be null.
  • Method Details

    • getNumberOfLabels

      public int getNumberOfLabels()
    • getLabelName

      public String getLabelName(int i)
      Get the label name at index i.
      Parameters:
      i - the index, must be >= 0 and < getNumberOfLabels().
      Returns:
      the label name at index i
    • getLabelValue

      public String getLabelValue(int i)
      Get the label value at index i.
      Parameters:
      i - the index, must be >= 0 and < getNumberOfLabels().
      Returns:
      the label value at index i
    • getValue

      public double getValue()
    • getTimestampMs

      public Long getTimestampMs()
      Returns:
      Unix timestamp or null if no timestamp is present.
    • sortedCopy

      private String[] sortedCopy(String... labels)
    • mapToArray

      public static String[] mapToArray(Map<String,String> labelMap)
      Convert the map to an array [key1, value1, key2, value2, ...].
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object