Monitoring (#3251)

* Add more plugin metrics

* Update dashboard to account for changed labels in upstream library and new plugin metrics
This commit is contained in:
Sebastian Göls 2024-07-14 21:11:07 +02:00 committed by GitHub
parent f87b63d6ee
commit 38ae309285
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 563 additions and 400 deletions

View file

@ -23,6 +23,7 @@
using System;
using System.Collections.Concurrent;
using System.Collections.Frozen;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Composition;
@ -69,6 +70,8 @@ internal sealed class MonitoringPlugin : OfficialPlugin, IDisposable, IOfficialG
private static bool Enabled => ASF.GlobalConfig?.IPC ?? GlobalConfig.DefaultIPC;
private static FrozenSet<Measurement<int>>? PluginMeasurements;
[JsonInclude]
[Required]
public override string Name => nameof(MonitoringPlugin);
@ -136,6 +139,12 @@ internal sealed class MonitoringPlugin : OfficialPlugin, IDisposable, IOfficialG
return;
}
PluginMeasurements = new[] {
new Measurement<int>(PluginsCore.ActivePlugins.Count),
new Measurement<int>(PluginsCore.ActivePlugins.Count(static plugin => plugin is OfficialPlugin), new KeyValuePair<string, object?>(TagNames.PluginType, "official")),
new Measurement<int>(PluginsCore.ActivePlugins.Count(static plugin => plugin is not OfficialPlugin), new KeyValuePair<string, object?>(TagNames.PluginType, "custom"))
}.ToFrozenSet();
Meter = new Meter(MeterName, Version.ToString());
Meter.CreateObservableGauge(
@ -158,7 +167,7 @@ internal sealed class MonitoringPlugin : OfficialPlugin, IDisposable, IOfficialG
Meter.CreateObservableGauge(
$"{MetricNamePrefix}_active_plugins",
static () => PluginsCore.ActivePlugins.Count,
static () => PluginMeasurements,
description: "Number of plugins currently loaded in ASF"
);

View file

@ -29,6 +29,7 @@ internal static class TagNames {
internal const string CurrencyCode = "currency";
internal const string Framework = "framework";
internal const string OS = "operating_system";
internal const string PluginType = "type";
internal const string Runtime = "runtime";
internal const string SteamID = "steamid";
internal const string TradeOfferResult = "result";