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