Skip to content

Commit f18a1d5

Browse files
committed
Misc monitoring stuff
1 parent 1302fd8 commit f18a1d5

File tree

1 file changed

+25
-16
lines changed

1 file changed

+25
-16
lines changed

ArchiSteamFarm.OfficialPlugins.Monitoring/MonitoringPlugin.cs

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
using System;
2525
using System.Collections.Concurrent;
26+
using System.Collections.Frozen;
2627
using System.Collections.Generic;
2728
using System.Composition;
2829
using System.Diagnostics.CodeAnalysis;
@@ -51,8 +52,23 @@ internal sealed class MonitoringPlugin : OfficialPlugin, IBot, IBotTradeOfferRes
5152
private const string MetricNamePrefix = "asf";
5253
private const string UnknownLabelValueFallback = "unknown";
5354

55+
private static readonly Measurement<byte> BuildInfo = new(
56+
1,
57+
new KeyValuePair<string, object?>(TagNames.Version, SharedInfo.Version.ToString()),
58+
new KeyValuePair<string, object?>(TagNames.Variant, Core.BuildInfo.Variant)
59+
);
60+
61+
private static readonly Measurement<byte> RuntimeInfo = new(
62+
1,
63+
new KeyValuePair<string, object?>(TagNames.Framework, OS.Framework ?? UnknownLabelValueFallback),
64+
new KeyValuePair<string, object?>(TagNames.Runtime, OS.Runtime ?? UnknownLabelValueFallback),
65+
new KeyValuePair<string, object?>(TagNames.OS, OS.Description ?? UnknownLabelValueFallback)
66+
);
67+
5468
private static bool Enabled => ASF.GlobalConfig?.IPC ?? GlobalConfig.DefaultIPC;
5569

70+
private static FrozenSet<Measurement<int>>? PluginMeasurements;
71+
5672
[JsonInclude]
5773
public override string Name => nameof(MonitoringPlugin);
5874

@@ -135,26 +151,23 @@ private void InitializeMeter() {
135151
return;
136152
}
137153

154+
PluginMeasurements = new HashSet<Measurement<int>>(3) {
155+
new(PluginsCore.ActivePlugins.Count),
156+
new(PluginsCore.ActivePlugins.Count(static plugin => plugin is OfficialPlugin), new KeyValuePair<string, object?>(TagNames.PluginType, "official")),
157+
new(PluginsCore.ActivePlugins.Count(static plugin => plugin is not OfficialPlugin), new KeyValuePair<string, object?>(TagNames.PluginType, "custom"))
158+
}.ToFrozenSet();
159+
138160
Meter = new Meter(MeterName, Version.ToString());
139161

140162
Meter.CreateObservableGauge(
141163
$"{MetricNamePrefix}_build_info",
142-
static () => new Measurement<byte>(
143-
1,
144-
new KeyValuePair<string, object?>(TagNames.Version, SharedInfo.Version.ToString()),
145-
new KeyValuePair<string, object?>(TagNames.Variant, BuildInfo.Variant)
146-
),
164+
static () => BuildInfo,
147165
description: "Build information about ASF in form of label values"
148166
);
149167

150168
Meter.CreateObservableGauge(
151169
$"{MetricNamePrefix}_runtime_info",
152-
static () => new Measurement<byte>(
153-
1,
154-
new KeyValuePair<string, object?>(TagNames.Framework, OS.Framework ?? UnknownLabelValueFallback),
155-
new KeyValuePair<string, object?>(TagNames.Runtime, OS.Runtime ?? UnknownLabelValueFallback),
156-
new KeyValuePair<string, object?>(TagNames.OS, OS.Description ?? UnknownLabelValueFallback)
157-
),
170+
static () => RuntimeInfo,
158171
description: "Runtime information about ASF in form of label values"
159172
);
160173

@@ -166,11 +179,7 @@ private void InitializeMeter() {
166179

167180
Meter.CreateObservableGauge(
168181
$"{MetricNamePrefix}_active_plugins",
169-
static () => new HashSet<Measurement<int>>(3) {
170-
new(PluginsCore.ActivePlugins.Count),
171-
new(PluginsCore.ActivePlugins.Count(static plugin => plugin is OfficialPlugin), new KeyValuePair<string, object?>(TagNames.PluginType, "official")),
172-
new(PluginsCore.ActivePlugins.Count(static plugin => plugin is not OfficialPlugin), new KeyValuePair<string, object?>(TagNames.PluginType, "custom"))
173-
},
182+
static () => PluginMeasurements,
174183
description: "Number of plugins currently loaded in ASF"
175184
);
176185

0 commit comments

Comments
 (0)