ObservableGauge<T>
Represents an observable instrument that reports non-additive values when the instrument is being observed, for example, the current room temperature. Call CreateObservableGauge to create the observable counter object.
using System.Collections.Generic;
using System.Runtime.CompilerServices;
namespace System.Diagnostics.Metrics
{
public sealed class ObservableGauge<T> : ObservableInstrument<T> where T : struct
{
private object _callback;
internal ObservableGauge(Meter meter, string name, Func<T> observeValue, string unit, string description)
: base(meter, name, unit, description)
{
if (observeValue == null)
throw new ArgumentNullException("observeValue");
_callback = observeValue;
Publish();
}
internal ObservableGauge(Meter meter, string name, Func<Measurement<T>> observeValue, string unit, string description)
: base(meter, name, unit, description)
{
if (observeValue == null)
throw new ArgumentNullException("observeValue");
_callback = observeValue;
Publish();
}
internal ObservableGauge(Meter meter, string name, Func<IEnumerable<Measurement<T>>> observeValues, string unit, string description)
: base(meter, name, unit, description)
{
if (observeValues == null)
throw new ArgumentNullException("observeValues");
_callback = observeValues;
Publish();
}
[return: System.Runtime.CompilerServices.Nullable(new byte[] {
1,
0,
0
})]
protected override IEnumerable<Measurement<T>> Observe()
{
return ObservableInstrument<T>.Observe(_callback);
}
}
}