Meter
Meter is the class responsible for creating and tracking the Instruments.
using System.Collections.Generic;
using System.Runtime.CompilerServices;
namespace System.Diagnostics.Metrics
{
[System.Runtime.CompilerServices.NullableContext(2)]
[System.Runtime.CompilerServices.Nullable(0)]
public class Meter : IDisposable
{
private static readonly List<Meter> s_allMeters = new List<Meter>();
private List<Instrument> _instruments = new List<Instrument>();
internal bool Disposed { get; set; }
[System.Runtime.CompilerServices.Nullable(1)]
public string Name {
[System.Runtime.CompilerServices.NullableContext(1)]
get;
}
public string Version { get; }
[System.Runtime.CompilerServices.NullableContext(1)]
public Meter(string name)
: this(name, null)
{
}
[System.Runtime.CompilerServices.NullableContext(1)]
public Meter(string name, [System.Runtime.CompilerServices.Nullable(2)] string version)
{
if (name == null)
throw new ArgumentNullException("name");
Name = name;
Version = version;
lock (Instrument.SyncObject) {
s_allMeters.Add(this);
}
GC.KeepAlive(MetricsEventSource.Log);
}
[return: System.Runtime.CompilerServices.Nullable(new byte[] {
1,
0
})]
public Counter<T> CreateCounter<[System.Runtime.CompilerServices.Nullable(0)] T>([System.Runtime.CompilerServices.Nullable(1)] string name, string unit = null, string description = null) where T : struct
{
return new Counter<T>(this, name, unit, description);
}
[return: System.Runtime.CompilerServices.Nullable(new byte[] {
1,
0
})]
public Histogram<T> CreateHistogram<[System.Runtime.CompilerServices.Nullable(0)] T>([System.Runtime.CompilerServices.Nullable(1)] string name, string unit = null, string description = null) where T : struct
{
return new Histogram<T>(this, name, unit, description);
}
[return: System.Runtime.CompilerServices.Nullable(new byte[] {
1,
0
})]
public UpDownCounter<T> CreateUpDownCounter<[System.Runtime.CompilerServices.Nullable(0)] T>([System.Runtime.CompilerServices.Nullable(1)] string name, string unit = null, string description = null) where T : struct
{
return new UpDownCounter<T>(this, name, unit, description);
}
[return: System.Runtime.CompilerServices.Nullable(new byte[] {
1,
0
})]
public ObservableUpDownCounter<T> CreateObservableUpDownCounter<[System.Runtime.CompilerServices.Nullable(0)] T>([System.Runtime.CompilerServices.Nullable(1)] string name, [System.Runtime.CompilerServices.Nullable(new byte[] {
1,
0
})] Func<T> observeValue, string unit = null, string description = null) where T : struct
{
return new ObservableUpDownCounter<T>(this, name, observeValue, unit, description);
}
[return: System.Runtime.CompilerServices.Nullable(new byte[] {
1,
0
})]
public ObservableUpDownCounter<T> CreateObservableUpDownCounter<[System.Runtime.CompilerServices.Nullable(0)] T>([System.Runtime.CompilerServices.Nullable(1)] string name, [System.Runtime.CompilerServices.Nullable(new byte[] {
1,
0,
0
})] Func<Measurement<T>> observeValue, string unit = null, string description = null) where T : struct
{
return new ObservableUpDownCounter<T>(this, name, observeValue, unit, description);
}
[return: System.Runtime.CompilerServices.Nullable(new byte[] {
1,
0
})]
public ObservableUpDownCounter<T> CreateObservableUpDownCounter<[System.Runtime.CompilerServices.Nullable(0)] T>([System.Runtime.CompilerServices.Nullable(1)] string name, [System.Runtime.CompilerServices.Nullable(new byte[] {
1,
1,
0,
0
})] Func<IEnumerable<Measurement<T>>> observeValues, string unit = null, string description = null) where T : struct
{
return new ObservableUpDownCounter<T>(this, name, observeValues, unit, description);
}
[return: System.Runtime.CompilerServices.Nullable(new byte[] {
1,
0
})]
public ObservableCounter<T> CreateObservableCounter<[System.Runtime.CompilerServices.Nullable(0)] T>([System.Runtime.CompilerServices.Nullable(1)] string name, [System.Runtime.CompilerServices.Nullable(new byte[] {
1,
0
})] Func<T> observeValue, string unit = null, string description = null) where T : struct
{
return new ObservableCounter<T>(this, name, observeValue, unit, description);
}
[return: System.Runtime.CompilerServices.Nullable(new byte[] {
1,
0
})]
public ObservableCounter<T> CreateObservableCounter<[System.Runtime.CompilerServices.Nullable(0)] T>([System.Runtime.CompilerServices.Nullable(1)] string name, [System.Runtime.CompilerServices.Nullable(new byte[] {
1,
0,
0
})] Func<Measurement<T>> observeValue, string unit = null, string description = null) where T : struct
{
return new ObservableCounter<T>(this, name, observeValue, unit, description);
}
[return: System.Runtime.CompilerServices.Nullable(new byte[] {
1,
0
})]
public ObservableCounter<T> CreateObservableCounter<[System.Runtime.CompilerServices.Nullable(0)] T>([System.Runtime.CompilerServices.Nullable(1)] string name, [System.Runtime.CompilerServices.Nullable(new byte[] {
1,
1,
0,
0
})] Func<IEnumerable<Measurement<T>>> observeValues, string unit = null, string description = null) where T : struct
{
return new ObservableCounter<T>(this, name, observeValues, unit, description);
}
[return: System.Runtime.CompilerServices.Nullable(new byte[] {
1,
0
})]
public ObservableGauge<T> CreateObservableGauge<[System.Runtime.CompilerServices.Nullable(0)] T>([System.Runtime.CompilerServices.Nullable(1)] string name, [System.Runtime.CompilerServices.Nullable(new byte[] {
1,
0
})] Func<T> observeValue, string unit = null, string description = null) where T : struct
{
return new ObservableGauge<T>(this, name, observeValue, unit, description);
}
[return: System.Runtime.CompilerServices.Nullable(new byte[] {
1,
0
})]
public ObservableGauge<T> CreateObservableGauge<[System.Runtime.CompilerServices.Nullable(0)] T>([System.Runtime.CompilerServices.Nullable(1)] string name, [System.Runtime.CompilerServices.Nullable(new byte[] {
1,
0,
0
})] Func<Measurement<T>> observeValue, string unit = null, string description = null) where T : struct
{
return new ObservableGauge<T>(this, name, observeValue, unit, description);
}
[return: System.Runtime.CompilerServices.Nullable(new byte[] {
1,
0
})]
public ObservableGauge<T> CreateObservableGauge<[System.Runtime.CompilerServices.Nullable(0)] T>([System.Runtime.CompilerServices.Nullable(1)] string name, [System.Runtime.CompilerServices.Nullable(new byte[] {
1,
1,
0,
0
})] Func<IEnumerable<Measurement<T>>> observeValues, string unit = null, string description = null) where T : struct
{
return new ObservableGauge<T>(this, name, observeValues, unit, description);
}
public void Dispose()
{
List<Instrument> list = null;
lock (Instrument.SyncObject) {
if (Disposed)
return;
Disposed = true;
s_allMeters.Remove(this);
list = _instruments;
_instruments = new List<Instrument>();
}
if (list != null) {
foreach (Instrument item in list) {
item.NotifyForUnpublishedInstrument();
}
}
}
internal bool AddInstrument(Instrument instrument)
{
if (!_instruments.Contains(instrument)) {
_instruments.Add(instrument);
return true;
}
return false;
}
internal static List<Instrument> GetPublishedInstruments()
{
List<Instrument> result = null;
if (s_allMeters.Count > 0) {
result = new List<Instrument>();
{
foreach (Meter s_allMeter in s_allMeters) {
foreach (Instrument instrument in s_allMeter._instruments) {
result.Add(instrument);
}
}
return result;
}
}
return result;
}
}
}