void.cat/VoidCat/Services/Stats/PrometheusStatsCollector.cs
2022-02-21 22:35:06 +00:00

27 lines
787 B
C#

using Prometheus;
using VoidCat.Services.Abstractions;
namespace VoidCat.Services.Stats;
public class PrometheusStatsCollector : IStatsCollector
{
private readonly Counter _egress =
Metrics.CreateCounter("egress", "Outgoing traffic from the site", "file");
private readonly Counter _ingress =
Metrics.CreateCounter("ingress", "Incoming traffic to the site", "file");
public ValueTask TrackIngress(Guid id, ulong amount)
{
_ingress.Inc(amount);
_ingress.WithLabels(id.ToString()).Inc(amount);
return ValueTask.CompletedTask;
}
public ValueTask TrackEgress(Guid id, ulong amount)
{
_egress.Inc(amount);
_egress.WithLabels(id.ToString()).Inc(amount);
return ValueTask.CompletedTask;
}
}