51 public double? WindowDelta {
get; init; }
54 public double? LastObservedSeconds {
get; init; }
57 public double? Mean => Count == 0 ? null : Sum / Count;
62 public static TelemetrySummary Combine(IEnumerable<TelemetrySummary> summaries)
64 ArgumentNullException.ThrowIfNull(summaries);
67 double? min =
null, max =
null, last =
null;
68 double? observed =
null, delta =
null;
72 foreach (var value
in summaries)
74 if (kind is not
null && kind != value.Kind)
75 throw new ArgumentException(
"Cannot combine different metric kinds.", nameof(summaries));
79 if (value.Availability > availability)
80 availability = value.Availability;
87 min = min is
null ? value.Minimum : Math.Min(min.Value, value.Minimum!.Value);
88 max = max is
null ? value.Maximum : Math.Max(max.Value, value.Maximum!.Value);
90 observed = value.LastObservedSeconds;
92 if (value.WindowDelta is { } change)
93 delta = (delta ?? 0) + change;
105 LastObservedSeconds = observed,
122 internal const long MaxRetainedMetricSummaries = 1_048_576;
125 internal const long MaxPublishedMetricSummariesPerSecond = 262_144;
128 public TimeSpan Interval {
get; init; } = TimeSpan.FromMilliseconds(250);
131 public int HistoryCapacity {
get; init; } = 120;
134 public int SourceCapacity {
get; init; } = 16;
137 public int MetricCapacity {
get; init; } = 128;
140 internal void Validate()
142 if (Interval < TimeSpan.FromMilliseconds(10) || Interval > TimeSpan.FromMinutes(1))
143 throw new ArgumentOutOfRangeException(nameof(Interval));
145 if (HistoryCapacity is < 1 or > 1024)
146 throw new ArgumentOutOfRangeException(nameof(HistoryCapacity));
148 if (SourceCapacity is < 1 or > 64)
149 throw new ArgumentOutOfRangeException(nameof(SourceCapacity));
151 if (MetricCapacity is < 8 or > 512)
152 throw new ArgumentOutOfRangeException(nameof(MetricCapacity));
154 long retainedMetricSummaries =
155 (long)HistoryCapacity * SourceCapacity * MetricCapacity;
157 if (retainedMetricSummaries > MaxRetainedMetricSummaries)
159 throw new ArgumentException(
160 $
"HistoryCapacity * SourceCapacity * MetricCapacity must not exceed {MaxRetainedMetricSummaries:N0} retained metric summaries.");
163 double publishedMetricSummariesPerSecond =
164 (double)SourceCapacity * MetricCapacity / Interval.TotalSeconds;
166 if (publishedMetricSummariesPerSecond > MaxPublishedMetricSummariesPerSecond)
168 throw new ArgumentException(
169 $
"SourceCapacity * MetricCapacity / Interval.TotalSeconds must not exceed {MaxPublishedMetricSummariesPerSecond:N0} configured metric summaries per second.");
182 double StartedSeconds,
184 IReadOnlyList<TelemetrySourceSnapshot> Sources,
188 public double ElapsedSeconds => EndedSeconds - StartedSeconds;
200 IReadOnlyDictionary<string, TelemetrySummary> Metrics);
record TelemetrySummary(TelemetryAvailability Availability, long Count, double Sum, double? Minimum, double? Maximum, double? Last)
Detached statistics for observations in one window; durations use milliseconds.
record TelemetrySourceSnapshot(long Id, string Name, string Backend, IReadOnlyDictionary< string, TelemetrySummary > Metrics)
Detached source identity, backend label, and measurements. No runtime objects are retained.
TelemetryAvailability
Whether an observation is meaningful for its source and window.
@ NotYetSampled
The measurement is supported but has no samples in this window.
@ NotApplicable
The measurement does not apply to this rendering path.
@ Available
At least one observation is present.
@ Unsupported
The source does not implement this measurement.
TelemetryMetricKind
How observations should be interpreted when combining windows.
@ Gauge
Observed state; use Last for current state, not the sum across windows.
@ Sample
Independent work samples; count divided by elapsed seconds gives cadence.
@ LifetimeCounter
Renderer-owned cumulative value; WindowDelta is relative to the previous observation.
record TelemetryOptions
Validated shared settings; configure only when collection is inactive.
record TelemetrySnapshot(long Generation, double StartedSeconds, double EndedSeconds, IReadOnlyList< TelemetrySourceSnapshot > Sources, bool Truncated)
Detached completed window. Sources can be observed asynchronously within its interval.