Files
git.stella-ops.org/src/Scanner/__Libraries/StellaOps.Scanner.Cache/ScannerCacheMetrics.cs
2025-10-28 15:10:40 +02:00

44 lines
2.2 KiB
C#

using System.Diagnostics.Metrics;
namespace StellaOps.Scanner.Cache;
public static class ScannerCacheMetrics
{
public const string MeterName = "StellaOps.Scanner.Cache";
private static readonly Meter Meter = new(MeterName, "1.0.0");
private static readonly Counter<long> LayerHits = Meter.CreateCounter<long>("scanner.layer_cache_hits_total");
private static readonly Counter<long> LayerMisses = Meter.CreateCounter<long>("scanner.layer_cache_misses_total");
private static readonly Counter<long> LayerEvictions = Meter.CreateCounter<long>("scanner.layer_cache_evictions_total");
private static readonly Histogram<long> LayerBytes = Meter.CreateHistogram<long>("scanner.layer_cache_bytes");
private static readonly Counter<long> FileCasHits = Meter.CreateCounter<long>("scanner.file_cas_hits_total");
private static readonly Counter<long> FileCasMisses = Meter.CreateCounter<long>("scanner.file_cas_misses_total");
private static readonly Counter<long> FileCasEvictions = Meter.CreateCounter<long>("scanner.file_cas_evictions_total");
private static readonly Histogram<long> FileCasBytes = Meter.CreateHistogram<long>("scanner.file_cas_bytes");
public static void RecordLayerHit(string layerDigest)
=> LayerHits.Add(1, new KeyValuePair<string, object?>("layer", layerDigest));
public static void RecordLayerMiss(string layerDigest)
=> LayerMisses.Add(1, new KeyValuePair<string, object?>("layer", layerDigest));
public static void RecordLayerEviction(string layerDigest)
=> LayerEvictions.Add(1, new KeyValuePair<string, object?>("layer", layerDigest));
public static void RecordLayerBytes(long bytes)
=> LayerBytes.Record(bytes);
public static void RecordFileCasHit(string sha256)
=> FileCasHits.Add(1, new KeyValuePair<string, object?>("sha256", sha256));
public static void RecordFileCasMiss(string sha256)
=> FileCasMisses.Add(1, new KeyValuePair<string, object?>("sha256", sha256));
public static void RecordFileCasEviction(string sha256)
=> FileCasEvictions.Add(1, new KeyValuePair<string, object?>("sha256", sha256));
public static void RecordFileCasBytes(long bytes)
=> FileCasBytes.Record(bytes);
}