Skip to content

Commit

Permalink
Fix observable counters
Browse files Browse the repository at this point in the history
  • Loading branch information
JustArchi committed May 28, 2024
1 parent 7023040 commit 17c4ec6
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 17 deletions.
16 changes: 8 additions & 8 deletions ArchiSteamFarm.OfficialPlugins.Monitoring/MonitoringPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -249,33 +249,33 @@ private void InitializeMeter() {
);

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),
Expand All @@ -287,12 +287,12 @@ private void InitializeMeter() {
);

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"
);
}
Expand Down
18 changes: 9 additions & 9 deletions ArchiSteamFarm.OfficialPlugins.Monitoring/TradeStatistics.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -45,8 +45,8 @@ internal void Include(ParseTradeResult result) {
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:
Expand Down

0 comments on commit 17c4ec6

Please sign in to comment.