Initial
This commit is contained in:
@@ -0,0 +1,84 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Prometheus;
|
||||
|
||||
namespace MareSynchronosShared.Metrics;
|
||||
|
||||
public class MareMetrics
|
||||
{
|
||||
public MareMetrics(ILogger<MareMetrics> logger, List<string> countersToServe, List<string> gaugesToServe)
|
||||
{
|
||||
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)
|
||||
{
|
||||
logger.LogInformation($"Creating Metric for Counter {gauge}");
|
||||
if (!string.Equals(gauge, MetricsAPI.GaugeConnections, StringComparison.OrdinalIgnoreCase))
|
||||
gauges.Add(gauge, Prometheus.Metrics.CreateGauge(gauge, gauge));
|
||||
else
|
||||
gauges.Add(gauge, Prometheus.Metrics.CreateGauge(gauge, gauge, new[] { "continent" }));
|
||||
}
|
||||
}
|
||||
|
||||
private readonly Dictionary<string, Counter> counters = new(StringComparer.Ordinal);
|
||||
|
||||
private readonly Dictionary<string, Gauge> gauges = new(StringComparer.Ordinal);
|
||||
|
||||
public void IncGaugeWithLabels(string gaugeName, double value = 1.0, params string[] labels)
|
||||
{
|
||||
if (gauges.TryGetValue(gaugeName, out Gauge gauge))
|
||||
{
|
||||
lock (gauge)
|
||||
gauge.WithLabels(labels).Inc(value);
|
||||
}
|
||||
}
|
||||
|
||||
public void DecGaugeWithLabels(string gaugeName, double value = 1.0, params string[] labels)
|
||||
{
|
||||
if (gauges.TryGetValue(gaugeName, out Gauge gauge))
|
||||
{
|
||||
lock (gauge)
|
||||
gauge.WithLabels(labels).Dec(value);
|
||||
}
|
||||
}
|
||||
|
||||
public void SetGaugeTo(string gaugeName, double value)
|
||||
{
|
||||
if (gauges.TryGetValue(gaugeName, out Gauge gauge))
|
||||
{
|
||||
lock (gauge)
|
||||
gauge.Set(value);
|
||||
}
|
||||
}
|
||||
|
||||
public void IncGauge(string gaugeName, double value = 1.0)
|
||||
{
|
||||
if (gauges.TryGetValue(gaugeName, out Gauge gauge))
|
||||
{
|
||||
lock (gauge)
|
||||
gauge.Inc(value);
|
||||
}
|
||||
}
|
||||
|
||||
public void DecGauge(string gaugeName, double value = 1.0)
|
||||
{
|
||||
if (gauges.TryGetValue(gaugeName, out Gauge gauge))
|
||||
{
|
||||
lock (gauge)
|
||||
gauge.Dec(value);
|
||||
}
|
||||
}
|
||||
|
||||
public void IncCounter(string counterName, double value = 1.0)
|
||||
{
|
||||
if (counters.TryGetValue(counterName, out Counter counter))
|
||||
{
|
||||
lock (counter)
|
||||
counter.Inc(value);
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,46 @@
|
||||
namespace MareSynchronosShared.Metrics;
|
||||
|
||||
public class MetricsAPI
|
||||
{
|
||||
public const string CounterInitializedConnections = "mare_initialized_connections";
|
||||
public const string GaugeConnections = "mare_connections";
|
||||
public const string GaugeAuthorizedConnections = "mare_authorized_connections";
|
||||
public const string GaugeAvailableWorkerThreads = "mare_available_threadpool";
|
||||
public const string GaugeAvailableIOWorkerThreads = "mare_available_threadpool_io";
|
||||
public const string GaugeUsersRegistered = "mare_users_registered";
|
||||
public const string CounterUsersRegisteredDeleted = "mare_users_registered_deleted";
|
||||
public const string GaugePairs = "mare_pairs";
|
||||
public const string GaugePairsPaused = "mare_pairs_paused";
|
||||
public const string GaugeFilesTotal = "mare_files";
|
||||
public const string GaugeFilesTotalColdStorage = "mare_files_cold";
|
||||
public const string GaugeFilesTotalSize = "mare_files_size";
|
||||
public const string GaugeFilesTotalSizeColdStorage = "mare_files_size_cold";
|
||||
public const string GaugeFilesDownloadingFromCache = "mare_files_downloading_from_cache";
|
||||
public const string GaugeFilesTasksWaitingForDownloadFromCache = "mare_files_waiting_for_dl";
|
||||
public const string CounterUserPushData = "mare_user_push";
|
||||
public const string CounterUserPushDataTo = "mare_user_push_to";
|
||||
public const string CounterAuthenticationRequests = "mare_auth_requests";
|
||||
public const string CounterAuthenticationCacheHits = "mare_auth_requests_cachehit";
|
||||
public const string CounterAuthenticationFailures = "mare_auth_requests_fail";
|
||||
public const string CounterAuthenticationSuccesses = "mare_auth_requests_success";
|
||||
public const string GaugeGroups = "mare_groups";
|
||||
public const string GaugeGroupPairs = "mare_groups_pairs";
|
||||
public const string GaugeGroupPairsPaused = "mare_groups_pairs_paused";
|
||||
public const string GaugeFilesUniquePastHour = "mare_files_unique_past_hour";
|
||||
public const string GaugeFilesUniquePastHourSize = "mare_files_unique_past_hour_size";
|
||||
public const string GaugeFilesUniquePastDay = "mare_files_unique_past_day";
|
||||
public const string GaugeFilesUniquePastDaySize = "mare_files_unique_past_day_size";
|
||||
public const string GaugeCurrentDownloads = "mare_current_downloads";
|
||||
public const string GaugeQueueFree = "mare_download_queue_free";
|
||||
public const string GaugeQueueActive = "mare_download_queue_active";
|
||||
public const string GaugeQueueInactive = "mare_download_queue_inactive";
|
||||
public const string GaugeDownloadQueue = "mare_download_queue";
|
||||
public const string GaugeDownloadQueueCancelled = "mare_download_queue_cancelled";
|
||||
public const string GaugeDownloadPriorityQueue = "mare_download_priority_queue";
|
||||
public const string GaugeDownloadPriorityQueueCancelled = "mare_download_priority_queue_cancelled";
|
||||
public const string CounterFileRequests = "mare_files_requests";
|
||||
public const string CounterFileRequestSize = "mare_files_request_size";
|
||||
public const string CounterAccountsCreated = "mare_accounts_created";
|
||||
public const string GaugeGposeLobbies = "mare_gpose_lobbies";
|
||||
public const string GaugeGposeLobbyUsers = "mare_gpose_lobby_users";
|
||||
}
|
Reference in New Issue
Block a user