Fix monitoring integration with actual prometheus (#3183)

* Downgrade OpenTelemetry.Exporter.Prometheus.AspNetCore due to issues with latest version

* Add unit to asf_bot_farming_minutes_remaining

* Upgrade some packages released last night (already tested to work)

* Don't forget about unit suffix

* Add build and runtime information metrics

It is not recommended to include this information as labels in all
metrics. Instead, we add two special metrics with a constant value of
"1" and restrict those static pieces of information to them

* Remove module version from metrics as it does not work

* Apply feedback

* Deduplicate code

* Reference related issue in upstream repo
This commit is contained in:
Sebastian Göls
2024-04-07 23:56:44 +02:00
committed by GitHub
parent 8e055fe587
commit 9016a5109d
7 changed files with 94 additions and 24 deletions

View File

@@ -50,6 +50,21 @@ internal sealed class MonitoringPlugin : OfficialPlugin, IWebServiceProvider, IG
private const string MetricNamePrefix = "asf";
private const string UnknownLabelValueFallback = "unknown";
private static readonly Measurement<int> BuildInfo = new(
1,
new KeyValuePair<string, object?>(TagNames.Version, SharedInfo.Version.ToString()),
new KeyValuePair<string, object?>(TagNames.Variant, SharedInfo.BuildInfo.Variant)
);
private static readonly Measurement<int> RuntimeInfo = new(
1,
new KeyValuePair<string, object?>(TagNames.Framework, OS.Framework ?? UnknownLabelValueFallback),
new KeyValuePair<string, object?>(TagNames.Runtime, OS.Runtime ?? UnknownLabelValueFallback),
new KeyValuePair<string, object?>(TagNames.OS, OS.Description ?? UnknownLabelValueFallback)
);
private static bool Enabled => ASF.GlobalConfig?.IPC ?? GlobalConfig.DefaultIPC;
[JsonInclude]
@@ -106,6 +121,18 @@ internal sealed class MonitoringPlugin : OfficialPlugin, IWebServiceProvider, IG
Meter = new Meter(MeterName, Version.ToString());
Meter.CreateObservableGauge(
$"{MetricNamePrefix}_build_info",
static () => BuildInfo,
description: "Build information about ASF in form of label values"
);
Meter.CreateObservableGauge(
$"{MetricNamePrefix}_runtime_info",
static () => RuntimeInfo,
description: "Runtime information about ASF in form of label values"
);
Meter.CreateObservableGauge(
$"{MetricNamePrefix}_ipc_banned_ips",
static () => ApiAuthenticationMiddleware.GetCurrentlyBannedIPs().Count(),
@@ -150,13 +177,15 @@ internal sealed class MonitoringPlugin : OfficialPlugin, IWebServiceProvider, IG
description: "Number of Steam groups each bot is in"
);
// Keep in mind that we use a unit here and the unit needs to be a suffix to the name
Meter.CreateObservableGauge(
$"{MetricNamePrefix}_bot_farming_minutes_remaining", static () => {
$"{MetricNamePrefix}_bot_farming_time_remaining_{Units.Minutes}", static () => {
ICollection<Bot> bots = Bot.Bots?.Values ?? Array.Empty<Bot>();
return bots.Select(static bot => new Measurement<double>(bot.CardsFarmer.TimeRemaining.TotalMinutes, new KeyValuePair<string, object?>(TagNames.BotName, bot.BotName), new KeyValuePair<string, object?>(TagNames.SteamID, bot.SteamID)));
},
description: "Approximate number of minutes remaining until each bot has finished farming all cards"
Units.Minutes,
"Approximate number of minutes remaining until each bot has finished farming all cards"
);
Meter.CreateObservableGauge(

View File

@@ -27,5 +27,10 @@ internal static class TagNames {
internal const string BotName = "bot";
internal const string BotState = "state";
internal const string CurrencyCode = "currency";
internal const string Framework = "framework";
internal const string OS = "operating_system";
internal const string Runtime = "runtime";
internal const string SteamID = "steamid";
internal const string Variant = "variant";
internal const string Version = "version";
}

View File

@@ -0,0 +1,28 @@
// ----------------------------------------------------------------------------------------------
// _ _ _ ____ _ _____
// / \ _ __ ___ | |__ (_)/ ___| | |_ ___ __ _ _ __ ___ | ___|__ _ _ __ _ __ ___
// / _ \ | '__|/ __|| '_ \ | |\___ \ | __|/ _ \ / _` || '_ ` _ \ | |_ / _` || '__|| '_ ` _ \
// / ___ \ | | | (__ | | | || | ___) || |_| __/| (_| || | | | | || _|| (_| || | | | | | | |
// /_/ \_\|_| \___||_| |_||_||____/ \__|\___| \__,_||_| |_| |_||_| \__,_||_| |_| |_| |_|
// ----------------------------------------------------------------------------------------------
// |
// Copyright 2015-2024 Łukasz "JustArchi" Domeradzki
// Contact: JustArchi@JustArchi.net
// |
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// |
// http://www.apache.org/licenses/LICENSE-2.0
// |
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
namespace ArchiSteamFarm.OfficialPlugins.Monitoring;
internal static class Units {
internal const string Minutes = "minutes";
}