50 lines
1.9 KiB
C#
50 lines
1.9 KiB
C#
using System.Diagnostics.Metrics;
|
|
|
|
namespace StellaOps.Excititor.WebService.Telemetry;
|
|
|
|
internal sealed class ChunkTelemetry
|
|
{
|
|
private readonly Counter<long> _ingestedTotal;
|
|
private readonly Histogram<long> _itemCount;
|
|
private readonly Histogram<long> _payloadBytes;
|
|
private readonly Histogram<double> _latencyMs;
|
|
|
|
public ChunkTelemetry(IMeterFactory meterFactory)
|
|
{
|
|
var meter = meterFactory.Create("StellaOps.Excititor.Chunks");
|
|
_ingestedTotal = meter.CreateCounter<long>(
|
|
name: "vex_chunks_ingested_total",
|
|
unit: "chunks",
|
|
description: "Chunks submitted to Excititor VEX ingestion.");
|
|
_itemCount = meter.CreateHistogram<long>(
|
|
name: "vex_chunks_item_count",
|
|
unit: "items",
|
|
description: "Item count per submitted chunk.");
|
|
_payloadBytes = meter.CreateHistogram<long>(
|
|
name: "vex_chunks_payload_bytes",
|
|
unit: "bytes",
|
|
description: "Payload size per submitted chunk.");
|
|
_latencyMs = meter.CreateHistogram<double>(
|
|
name: "vex_chunks_latency_ms",
|
|
unit: "ms",
|
|
description: "End-to-end processing latency per chunk request.");
|
|
}
|
|
|
|
public void RecordIngested(string? tenant, string? source, string status, string? reason, long itemCount, long payloadBytes, double latencyMs)
|
|
{
|
|
var tags = new KeyValuePair<string, object?>[]
|
|
{
|
|
new("tenant", tenant ?? string.Empty),
|
|
new("source", source ?? string.Empty),
|
|
new("status", status),
|
|
new("reason", string.IsNullOrWhiteSpace(reason) ? string.Empty : reason)
|
|
};
|
|
|
|
var tagSpan = tags.AsSpan();
|
|
_ingestedTotal.Add(1, tagSpan);
|
|
_itemCount.Record(itemCount, tagSpan);
|
|
_payloadBytes.Record(payloadBytes, tagSpan);
|
|
_latencyMs.Record(latencyMs, tagSpan);
|
|
}
|
|
}
|