mirror of
https://github.com/LBPUnion/ProjectLighthouse.git
synced 2025-08-01 09:48:37 +00:00
Log recent matches for individual games to influx (#230)
This commit is contained in:
parent
dee575f711
commit
d03179997a
2 changed files with 37 additions and 4 deletions
|
@ -1,9 +1,12 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using InfluxDB.Client;
|
||||
using InfluxDB.Client.Writes;
|
||||
using Kettu;
|
||||
using LBPUnion.ProjectLighthouse.Logging;
|
||||
using LBPUnion.ProjectLighthouse.Types;
|
||||
using LBPUnion.ProjectLighthouse.Types.Settings;
|
||||
|
||||
namespace LBPUnion.ProjectLighthouse.Helpers;
|
||||
|
@ -12,6 +15,15 @@ public static class InfluxHelper
|
|||
{
|
||||
public static readonly InfluxDBClient Client = InfluxDBClientFactory.Create(ServerSettings.Instance.InfluxUrl, ServerSettings.Instance.InfluxToken);
|
||||
|
||||
private static readonly List<GameVersion> gameVersions = new()
|
||||
{
|
||||
GameVersion.LittleBigPlanet1,
|
||||
GameVersion.LittleBigPlanet2,
|
||||
GameVersion.LittleBigPlanet3,
|
||||
GameVersion.LittleBigPlanetVita,
|
||||
GameVersion.LittleBigPlanetPSP,
|
||||
};
|
||||
|
||||
public static async void Log()
|
||||
{
|
||||
using WriteApi writeApi = Client.GetWriteApi();
|
||||
|
@ -19,6 +31,15 @@ public static class InfluxHelper
|
|||
.Field("playerCount", await StatisticsHelper.RecentMatches())
|
||||
.Field("slotCount", await StatisticsHelper.SlotCount());
|
||||
|
||||
foreach (GameVersion gameVersion in gameVersions)
|
||||
{
|
||||
PointData gamePoint = PointData.Measurement("lighthouse")
|
||||
.Tag("game", gameVersion.ToString())
|
||||
.Field("playerCountGame", await StatisticsHelper.RecentMatchesForGame(gameVersion));
|
||||
|
||||
writeApi.WritePoint(ServerSettings.Instance.InfluxBucket, ServerSettings.Instance.InfluxOrg, gamePoint);
|
||||
}
|
||||
|
||||
writeApi.WritePoint(ServerSettings.Instance.InfluxBucket, ServerSettings.Instance.InfluxOrg, point);
|
||||
|
||||
writeApi.Flush();
|
||||
|
@ -34,10 +55,17 @@ public static class InfluxHelper
|
|||
{
|
||||
while (true)
|
||||
{
|
||||
#pragma warning disable CS4014
|
||||
Log();
|
||||
#pragma warning restore CS4014
|
||||
// Logger.Log("Logged.", LoggerLevelInflux.Instance);
|
||||
try
|
||||
{
|
||||
Log();
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
Logger.Log("Exception while logging: ", LoggerLevelInflux.Instance);
|
||||
|
||||
foreach (string line in e.ToString().Split("\n")) Logger.Log(line, LoggerLevelInflux.Instance);
|
||||
}
|
||||
|
||||
Thread.Sleep(60000);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using LBPUnion.ProjectLighthouse.Types;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace LBPUnion.ProjectLighthouse.Helpers;
|
||||
|
@ -10,6 +11,10 @@ public static class StatisticsHelper
|
|||
|
||||
public static async Task<int> RecentMatches() => await database.LastContacts.Where(l => TimestampHelper.Timestamp - l.Timestamp < 300).CountAsync();
|
||||
|
||||
public static async Task<int> RecentMatchesForGame
|
||||
(GameVersion gameVersion)
|
||||
=> await database.LastContacts.Where(l => TimestampHelper.Timestamp - l.Timestamp < 300 && l.GameVersion == gameVersion).CountAsync();
|
||||
|
||||
public static async Task<int> SlotCount() => await database.Slots.CountAsync();
|
||||
|
||||
public static async Task<int> UserCount() => await database.Users.CountAsync(u => !u.Banned);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue