Files
ClubPenguinServer/MareSynchronosServer/MareSynchronosShared/Metrics/MareMetrics.cs
rootdarkarchon bff21ead95 Syncshells (#11)
* some groups stuff

* further groups rework

* fixes for pause changes

* adjsut timeout interval

* fixes and namespace change to file scoped

* more fixes

* further implement groups

* fix change group ownership

* add some more stuff for groups

* more fixes and additions

* some fixes based on analyzers, add shard info to ui

* add discord command, cleanup

* fix regex

* add group migration and deletion on user deletion

* add api method for client to check health of connection

* adjust regex for vanity

* fixes for server and bot

* fixes some string comparison in linq queries

* fixes group leave and sets alias to null

* fix syntax in changeownership

* add better logging, fixes for group leaving

* fixes for group leave

Co-authored-by: Stanley Dimant <root.darkarchon@outlook.com>
2022-10-04 14:13:43 +02:00

55 lines
1.4 KiB
C#

using Prometheus;
namespace MareSynchronosShared.Metrics;
public class MareMetrics
{
public MareMetrics(List<string> countersToServe, List<string> gaugesToServe)
{
foreach(var counter in countersToServe)
{
counters.Add(counter, Prometheus.Metrics.CreateCounter(counter, counter));
}
foreach(var gauge in gaugesToServe)
{
gauges.Add(gauge, Prometheus.Metrics.CreateGauge(gauge, gauge));
}
}
private readonly Dictionary<string, Counter> counters = new(StringComparer.Ordinal);
private readonly Dictionary<string, Gauge> gauges = new(StringComparer.Ordinal);
public void SetGaugeTo(string gaugeName, double value)
{
if (gauges.ContainsKey(gaugeName))
{
gauges[gaugeName].IncTo(value);
}
}
public void IncGauge(string gaugeName, double value = 1.0)
{
if (gauges.ContainsKey(gaugeName))
{
gauges[gaugeName].Inc(value);
}
}
public void DecGauge(string gaugeName, double value = 1.0)
{
if (gauges.ContainsKey(gaugeName))
{
gauges[gaugeName].Dec(value);
}
}
public void IncCounter(string counterName, double value = 1.0)
{
if (counters.ContainsKey(counterName))
{
counters[counterName].Inc(value);
}
}
}