43 lines
1.1 KiB
C#
43 lines
1.1 KiB
C#
using System;
|
|
using System.Diagnostics;
|
|
using System.Diagnostics.Metrics;
|
|
|
|
namespace StellaOps.Provcache;
|
|
|
|
public static partial class ProvcacheTelemetry
|
|
{
|
|
/// <summary>
|
|
/// Record operation latency.
|
|
/// </summary>
|
|
/// <param name="operation">The operation type.</param>
|
|
/// <param name="duration">The operation duration.</param>
|
|
public static void RecordLatency(string operation, TimeSpan duration)
|
|
{
|
|
if (string.IsNullOrWhiteSpace(operation))
|
|
return;
|
|
|
|
var seconds = duration.TotalSeconds;
|
|
if (double.IsNaN(seconds) || double.IsInfinity(seconds) || seconds < 0)
|
|
seconds = 0d;
|
|
|
|
var tags = new TagList
|
|
{
|
|
{ "operation", operation }
|
|
};
|
|
|
|
_latencyHistogram.Record(seconds, tags);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Record cache entry size.
|
|
/// </summary>
|
|
/// <param name="bytes">The size in bytes.</param>
|
|
public static void RecordEntrySize(long bytes)
|
|
{
|
|
if (bytes < 0)
|
|
return;
|
|
|
|
_entrySizeHistogram.Record(bytes);
|
|
}
|
|
}
|