Fix observable counters

This commit is contained in:
Łukasz Domeradzki 2024-05-28 21:38:56 +02:00
parent 7023040882
commit 17c4ec6790
No known key found for this signature in database
GPG key ID: 6B138B4C64555AEA
2 changed files with 17 additions and 17 deletions

View file

@ -249,33 +249,33 @@ internal sealed class MonitoringPlugin : OfficialPlugin, IDisposable, IOfficialG
);
Meter.CreateObservableCounter(
$"{MetricNamePrefix}_bot_trades", () => TradeStatistics.SelectMany<KeyValuePair<Bot, TradeStatistics>, Measurement<uint>>(
$"{MetricNamePrefix}_bot_trades", () => TradeStatistics.SelectMany<KeyValuePair<Bot, TradeStatistics>, Measurement<int>>(
static kv => [
new Measurement<uint>(
new Measurement<int>(
kv.Value.AcceptedOffers,
new KeyValuePair<string, object?>(TagNames.BotName, kv.Key.BotName),
new KeyValuePair<string, object?>(TagNames.SteamID, kv.Key.SteamID),
new KeyValuePair<string, object?>(TagNames.TradeOfferResult, "accepted")
),
new Measurement<uint>(
new Measurement<int>(
kv.Value.RejectedOffers,
new KeyValuePair<string, object?>(TagNames.BotName, kv.Key.BotName),
new KeyValuePair<string, object?>(TagNames.SteamID, kv.Key.SteamID),
new KeyValuePair<string, object?>(TagNames.TradeOfferResult, "rejected")
),
new Measurement<uint>(
new Measurement<int>(
kv.Value.IgnoredOffers,
new KeyValuePair<string, object?>(TagNames.BotName, kv.Key.BotName),
new KeyValuePair<string, object?>(TagNames.SteamID, kv.Key.SteamID),
new KeyValuePair<string, object?>(TagNames.TradeOfferResult, "ignored")
),
new Measurement<uint>(
new Measurement<int>(
kv.Value.BlacklistedOffers,
new KeyValuePair<string, object?>(TagNames.BotName, kv.Key.BotName),
new KeyValuePair<string, object?>(TagNames.SteamID, kv.Key.SteamID),
new KeyValuePair<string, object?>(TagNames.TradeOfferResult, "blacklisted")
),
new Measurement<uint>(
new Measurement<int>(
kv.Value.ConfirmedOffers,
new KeyValuePair<string, object?>(TagNames.BotName, kv.Key.BotName),
new KeyValuePair<string, object?>(TagNames.SteamID, kv.Key.SteamID),
@ -287,12 +287,12 @@ internal sealed class MonitoringPlugin : OfficialPlugin, IDisposable, IOfficialG
);
Meter.CreateObservableCounter(
$"{MetricNamePrefix}_bot_items_given", () => TradeStatistics.Select(static kv => new Measurement<uint>(kv.Value.ItemsGiven, new KeyValuePair<string, object?>(TagNames.BotName, kv.Key.BotName), new KeyValuePair<string, object?>(TagNames.SteamID, kv.Key.SteamID))),
$"{MetricNamePrefix}_bot_items_given", () => TradeStatistics.Select(static kv => new Measurement<int>(kv.Value.ItemsGiven, new KeyValuePair<string, object?>(TagNames.BotName, kv.Key.BotName), new KeyValuePair<string, object?>(TagNames.SteamID, kv.Key.SteamID))),
description: "Items given per bot"
);
Meter.CreateObservableCounter(
$"{MetricNamePrefix}_bot_items_received", () => TradeStatistics.Select(static kv => new Measurement<uint>(kv.Value.ItemsReceived, new KeyValuePair<string, object?>(TagNames.BotName, kv.Key.BotName), new KeyValuePair<string, object?>(TagNames.SteamID, kv.Key.SteamID))),
$"{MetricNamePrefix}_bot_items_received", () => TradeStatistics.Select(static kv => new Measurement<int>(kv.Value.ItemsReceived, new KeyValuePair<string, object?>(TagNames.BotName, kv.Key.BotName), new KeyValuePair<string, object?>(TagNames.SteamID, kv.Key.SteamID))),
description: "Items received per bot"
);
}

View file

@ -29,13 +29,13 @@ namespace ArchiSteamFarm.OfficialPlugins.Monitoring;
internal sealed class TradeStatistics {
private readonly object Lock = new();
internal uint AcceptedOffers { get; private set; }
internal uint BlacklistedOffers { get; private set; }
internal uint ConfirmedOffers { get; private set; }
internal uint IgnoredOffers { get; private set; }
internal uint ItemsGiven { get; private set; }
internal uint ItemsReceived { get; private set; }
internal uint RejectedOffers { get; private set; }
internal int AcceptedOffers { get; private set; }
internal int BlacklistedOffers { get; private set; }
internal int ConfirmedOffers { get; private set; }
internal int IgnoredOffers { get; private set; }
internal int ItemsGiven { get; private set; }
internal int ItemsReceived { get; private set; }
internal int RejectedOffers { get; private set; }
internal void Include(ParseTradeResult result) {
ArgumentNullException.ThrowIfNull(result);
@ -45,8 +45,8 @@ internal sealed class TradeStatistics {
case ParseTradeResult.EResult.Accepted when result.Confirmed:
ConfirmedOffers++;
ItemsGiven += (uint) (result.ItemsToGive?.Count ?? 0);
ItemsReceived += (uint) (result.ItemsToReceive?.Count ?? 0);
ItemsGiven += result.ItemsToGive?.Count ?? 0;
ItemsReceived += result.ItemsToReceive?.Count ?? 0;
goto case ParseTradeResult.EResult.Accepted;
case ParseTradeResult.EResult.Accepted: