mirror of
https://github.com/Caraxi/mare.server.git
synced 2025-12-12 22:17:22 +01:00
adjust metrics
This commit is contained in:
parent
5c9b15545c
commit
90ccfe4162
5 changed files with 39 additions and 47 deletions
|
|
@ -11,7 +11,7 @@ namespace MareSynchronosShared.Authentication;
|
|||
|
||||
public class SecretKeyAuthenticatorService
|
||||
{
|
||||
private readonly MareMetrics metrics;
|
||||
private readonly MareMetrics _metrics;
|
||||
private readonly IServiceScopeFactory _serviceScopeFactory;
|
||||
private readonly ILogger<SecretKeyAuthenticatorService> _logger;
|
||||
private readonly ConcurrentDictionary<string, SecretKeyAuthReply> _cachedPositiveResponses = new(StringComparer.Ordinal);
|
||||
|
|
@ -34,17 +34,17 @@ public class SecretKeyAuthenticatorService
|
|||
logger.LogInformation("Whitelisted IP: " + ip);
|
||||
}
|
||||
|
||||
this.metrics = metrics;
|
||||
_metrics = metrics;
|
||||
_serviceScopeFactory = serviceScopeFactory;
|
||||
}
|
||||
|
||||
internal async Task<SecretKeyAuthReply> AuthorizeAsync(string ip, string secretKey)
|
||||
{
|
||||
metrics.IncCounter(MetricsAPI.CounterAuthenticationRequests);
|
||||
_metrics.IncCounter(MetricsAPI.CounterAuthenticationRequests);
|
||||
|
||||
if (_cachedPositiveResponses.TryGetValue(secretKey, out var cachedPositiveResponse))
|
||||
{
|
||||
metrics.IncCounter(MetricsAPI.CounterAuthenticationCacheHits);
|
||||
_metrics.IncCounter(MetricsAPI.CounterAuthenticationCacheHits);
|
||||
return cachedPositiveResponse;
|
||||
}
|
||||
|
||||
|
|
@ -75,7 +75,7 @@ public class SecretKeyAuthenticatorService
|
|||
|
||||
if (reply.Success)
|
||||
{
|
||||
metrics.IncCounter(MetricsAPI.CounterAuthenticationSuccesses);
|
||||
_metrics.IncCounter(MetricsAPI.CounterAuthenticationSuccesses);
|
||||
|
||||
_cachedPositiveResponses[secretKey] = reply;
|
||||
_ = Task.Run(async () =>
|
||||
|
|
@ -95,7 +95,7 @@ public class SecretKeyAuthenticatorService
|
|||
|
||||
private SecretKeyAuthReply AuthenticationFailure(string ip)
|
||||
{
|
||||
metrics.IncCounter(MetricsAPI.CounterAuthenticationFailures);
|
||||
_metrics.IncCounter(MetricsAPI.CounterAuthenticationFailures);
|
||||
|
||||
_logger.LogWarning("Failed authorization from {ip}", ip);
|
||||
if (!_whitelistedIps.Any(w => ip.Contains(w, StringComparison.OrdinalIgnoreCase)))
|
||||
|
|
|
|||
|
|
@ -1,18 +1,22 @@
|
|||
using Prometheus;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Prometheus;
|
||||
|
||||
namespace MareSynchronosShared.Metrics;
|
||||
|
||||
public class MareMetrics
|
||||
{
|
||||
public MareMetrics(List<string> countersToServe, List<string> gaugesToServe)
|
||||
public MareMetrics(ILogger<MareMetrics> logger, List<string> countersToServe, List<string> gaugesToServe)
|
||||
{
|
||||
foreach(var counter in countersToServe)
|
||||
logger.LogInformation("Initializing MareMetrics");
|
||||
foreach (var counter in countersToServe)
|
||||
{
|
||||
logger.LogInformation($"Creating Metric for Counter {counter}");
|
||||
counters.Add(counter, Prometheus.Metrics.CreateCounter(counter, counter));
|
||||
}
|
||||
|
||||
foreach(var gauge in gaugesToServe)
|
||||
foreach (var gauge in gaugesToServe)
|
||||
{
|
||||
logger.LogInformation($"Creating Metric for Counter {gauge}");
|
||||
gauges.Add(gauge, Prometheus.Metrics.CreateGauge(gauge, gauge));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue