-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
125 additions
and
160 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 0 additions & 71 deletions
71
BanchoMultiplayerBot.Host.Web/Statistics/StatisticsController.cs
This file was deleted.
Oops, something went wrong.
17 changes: 0 additions & 17 deletions
17
BanchoMultiplayerBot.Host.Web/Statistics/StatisticsLobbyData.cs
This file was deleted.
Oops, something went wrong.
29 changes: 0 additions & 29 deletions
29
BanchoMultiplayerBot.Host.Web/Statistics/StatisticsSnapshot.cs
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
namespace BanchoMultiplayerBot.Behaviour; | ||
|
||
/// <summary> | ||
/// Behaviour to provide some anonymous statistics for the bot, such as "games played", | ||
/// "games aborted", "player count", "unique amount of players last hour". | ||
/// </summary> | ||
public class StatisticsBehaviour : IBotBehaviour | ||
{ | ||
private Lobby _lobby = null!; | ||
private readonly List<Tuple<string, DateTime>> _players = new(); | ||
|
||
public void Setup(Lobby lobby) | ||
{ | ||
_lobby = lobby; | ||
|
||
_lobby.MultiplayerLobby.OnMatchFinished += () => | ||
{ | ||
_lobby.Bot.RuntimeInfo.Statistics.GamesPlayed.WithLabels(_lobby.LobbyLabel).Inc(); | ||
}; | ||
|
||
_lobby.MultiplayerLobby.OnMatchAborted += () => | ||
{ | ||
_lobby.Bot.RuntimeInfo.Statistics.GamesAborted.WithLabels(_lobby.LobbyLabel).Inc(); | ||
}; | ||
|
||
_lobby.MultiplayerLobby.OnPlayerJoined += (e) => | ||
{ | ||
if (_players.All(x => x.Item1 != e.Name)) | ||
{ | ||
_players.Add(new Tuple<string, DateTime>(e.Name, DateTime.Now)); | ||
} | ||
|
||
_players.RemoveAll(x => DateTime.Now > x.Item2.AddHours(1)); | ||
|
||
_lobby.Bot.RuntimeInfo.Statistics.Players.WithLabels(_lobby.LobbyLabel).Set(_lobby.MultiplayerLobby.Players.Count); | ||
_lobby.Bot.RuntimeInfo.Statistics.UniquePlayers.WithLabels(_lobby.LobbyLabel).Set(_players.Count); | ||
}; | ||
|
||
_lobby.MultiplayerLobby.OnPlayerDisconnected += (e) => | ||
{ | ||
_lobby.Bot.RuntimeInfo.Statistics.Players.WithLabels(_lobby.LobbyLabel).Set(_lobby.MultiplayerLobby.Players.Count); | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
using Prometheus; | ||
|
||
namespace BanchoMultiplayerBot.Data; | ||
|
||
/// <summary> | ||
/// All statistics available through the metric endpoint if enabled. All statistics provided by the bot is anonymous. | ||
/// </summary> | ||
public class BotStatistics | ||
{ | ||
|
||
public Gauge IsConnected { get; } = Metrics.CreateGauge("IsConnected", "If the bot is connected to Bancho."); | ||
|
||
public Counter MessagesSent { get; } = Metrics.CreateCounter("MessagesSent", "Number of messages sent"); | ||
public Counter MessagesReceived { get; } = Metrics.CreateCounter("MessagesReceived", "Number of messages received"); | ||
public Gauge MessageSendQueue { get; } = Metrics.CreateGauge("MessageQueue", "Numbers of messages currently in queue to be sent."); | ||
|
||
public Counter ApiRequests { get; } = Metrics.CreateCounter("TotalApiRequests", "Total amount of API requests."); | ||
public Counter ApiErrors { get; } = Metrics.CreateCounter("TotalApiErrors", "Total amount of API errors."); | ||
public Histogram ApiRequestTime { get; } = Metrics.CreateHistogram("ApiRequestTime", "Time for each API request."); | ||
|
||
public Gauge Players { get; } = Metrics.CreateGauge("Players", "Total amount of players in each lobby", "Lobby"); | ||
public Gauge UniquePlayers { get; } = Metrics.CreateGauge("UniquePlayers", "Amount of unique players per hour", "Lobby"); | ||
public Gauge MapViolations { get; } = Metrics.CreateGauge("MapViolations", "Total amount of map violations in each lobby", "Lobby"); | ||
public Gauge GamesPlayed { get; } = Metrics.CreateGauge("GamesPlayed", "Total amount of games played in each lobby", "Lobby"); | ||
public Gauge GamesAborted { get; } = Metrics.CreateGauge("GamesAborted", "Total amount of games aborted in each lobby", "Lobby"); | ||
public Gauge HostSkipCount { get; } = Metrics.CreateGauge("HostSkipCount", "Total amount of host skips in each lobby", "Lobby"); | ||
public Histogram MapLength { get; } = Metrics.CreateHistogram("MapLength", "Length of the last map played", "Lobby"); | ||
public Histogram MapPickTime { get; } = Metrics.CreateHistogram("MapPickTime", "Time it took to pick a map", "Lobby"); | ||
|
||
} |
Oops, something went wrong.