This is probably a conversation better suited to
the metrics-user group as folks there will have the most up-to-date context.
Reading back through the thread starter, this point you made stood out. "Since Prometheus "pulls" the values from the process it's entirely possible that not all the values that were set to the gauge will later show in Prometheus' database." Is this ultimately the issue you're concerned about? That some changes in the gauge's value may go unnoticed by Prometheus due to the polling frequency? If so, I'm not certain there's much you're going to be able to do about that. Gauge is, ultimately, a point in time reading. This is why counters, timers, meters, and histograms exist…they're able to assimilate ongoing activity and expose that in a way that allows most of the necessary information to be conveyed regardless of the polling interval.
You could reduce the polling interval, but then you'll be trading system resources for data freshness. So assess how valuable it is to "see" every tick of the gauge. You could also try something a bit unconventional and implement a gauge that stores the last N changes/last N <timeunit> of changes, but then you're putting the responsibility of making sense of that on whatever polls the metric (like building soft counters/timers/meters/histograms out of gauges).
I don't feel like there's anything necessarily wrong with a SettableGauge. I've certainly done the equivalent of it in the past, with my code updating some member variable and the getValue() implementation reading from that. But even that doesn't solve the problem of missing updates in your metrics system of choice. Maybe I don't understand what this implementation of SettableGauge would look like. Is it simply this or something more complex?
class SettableGauge<T> implements Gauge<T> {
private AtomicReference<T> value;
public T getValue() {
return value.get();
}
public void setValue(T value) {
this.value.set(value);
}
}
Ryan