001package io.prometheus.metrics.core.datapoints;
002
003import io.prometheus.metrics.annotations.StableApi;
004import io.prometheus.metrics.model.snapshots.Labels;
005
006/**
007 * Represents a single gauge data point, i.e. a single line for a gauge metric in Prometheus text
008 * format.
009 *
010 * <p>See JavaDoc of {@link CounterDataPoint} on how using data points directly can improve
011 * performance.
012 */
013@StableApi
014public interface GaugeDataPoint extends DataPoint, TimerApi {
015
016  /** Add one. */
017  default void inc() {
018    inc(1.0);
019  }
020
021  /** Add {@code amount}. */
022  void inc(double amount);
023
024  /** Add one, and create a custom exemplar with the given labels. */
025  default void incWithExemplar(Labels labels) {
026    incWithExemplar(1.0, labels);
027  }
028
029  /** Add {@code amount}, and create a custom exemplar with the given labels. */
030  void incWithExemplar(double amount, Labels labels);
031
032  /** Subtract one. */
033  default void dec() {
034    inc(-1.0);
035  }
036
037  /** Subtract {@code amount}. */
038  default void dec(double amount) {
039    inc(-amount);
040  }
041
042  /** Subtract one, and create a custom exemplar with the given labels. */
043  default void decWithExemplar(Labels labels) {
044    incWithExemplar(-1.0, labels);
045  }
046
047  /** Subtract {@code amount}, and create a custom exemplar with the given labels. */
048  default void decWithExemplar(double amount, Labels labels) {
049    incWithExemplar(-amount, labels);
050  }
051
052  /** Set the gauge to {@code value}. */
053  void set(double value);
054
055  /** Get the current value. */
056  double get();
057
058  /** Set the gauge to {@code value}, and create a custom exemplar with the given labels. */
059  void setWithExemplar(double value, Labels labels);
060
061  @Override
062  default Timer startTimer() {
063    return new Timer(this::set);
064  }
065}