/// <summary> /// Helper class to human-friendly render units. /// </summary> /// <param name="unit">The observation unit.</param> /// <returns>The human friendly string. Or empty string.</returns> public static string GetStringFromUnit(ObservationUnits unit) { switch (unit) { case ObservationUnits.Default: return(string.Empty); case ObservationUnits.KmPerHour: return("km/h"); case ObservationUnits.DegreesCelcius: return("\u00B0C"); case ObservationUnits.GramsPerCubicMeter: return("g/m3"); case ObservationUnits.HectoPascal: return("hPa"); case ObservationUnits.PartsPerBillion: return("ppb"); case ObservationUnits.PartsPerMillion: return("ppm"); case ObservationUnits.Percentage: return("%"); case ObservationUnits.Millimeter: return("mm"); } return(string.Empty); }
/// <summary> /// Initializes a new instance of the <see cref="Observation"/> class. /// </summary> /// <param name="value">The value to add.</param> /// <param name="when">The sample timestamp.</param> /// <param name="name">The name for the observation.</param> /// <param name="units">The units the observation is in.</param> /// <param name="observationType">The type of the observation.</param> public Observation(double value, DateTime when, string name, ObservationUnits units, ObservationType observationType) { this.Value = value; this.Observed = when; this.Name = name; this.ObservationType = observationType; this.Units = units; }
/// <inheritdoc/> public void AddFinalObservation(double value, string name, ObservationUnits units) { this.Observations.Add(new Observation(value, this.sampleTime, name, units, ObservationType.CALIBRATED)); }
/// <inheritdoc/> public void AddIntermediateObservation(double value, string name, ObservationUnits units) { this.Observations.Add(new Observation(value, this.sampleTime, name, units, ObservationType.RAW)); }
/// <summary> /// Similar to <see cref="TimerExtensions.NewTimer(Prometheus.IObserver)"/> but observes the time in the specified unit. /// </summary> public static IDisposable Measure(this IObserver observer, ObservationUnits units = ObservationUnits.Seconds) => new HistogramMeasureContext(observer, units);
public HistogramMeasureContext(IObserver observer, ObservationUnits units) { _observer = observer; _units = units; }