mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2026-10-05 20:33:44 +00:00
feat(dashboard): track the UGC server like auth and chat
Online state with the time it came up, down/up alerts, a UGC column in the health history, /api/servers (every server with its process memory and CPU) and /api/servers/ugc, and UGC gauges for Prometheus. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -6,6 +6,9 @@
|
||||
namespace ServerState {
|
||||
ServerStatus g_AuthStatus{};
|
||||
ServerStatus g_ChatStatus{};
|
||||
ServerStatus g_UgcStatus{};
|
||||
bool g_UgcEnabled{};
|
||||
uint32_t g_UgcPid{};
|
||||
std::vector<WorldInstanceInfo> g_WorldInstances{};
|
||||
std::mutex g_StatusMutex{};
|
||||
}
|
||||
@@ -16,6 +19,8 @@ protected:
|
||||
std::lock_guard lock(ServerState::g_StatusMutex);
|
||||
ServerState::g_AuthStatus = {};
|
||||
ServerState::g_ChatStatus = {};
|
||||
ServerState::g_UgcStatus = {};
|
||||
ServerState::g_UgcEnabled = false;
|
||||
ServerState::g_WorldInstances.clear();
|
||||
}
|
||||
};
|
||||
@@ -25,6 +30,8 @@ TEST_F(ServerStateTest, DefaultStateAllOffline) {
|
||||
|
||||
EXPECT_FALSE(json["auth"]["online"].get<bool>());
|
||||
EXPECT_FALSE(json["chat"]["online"].get<bool>());
|
||||
EXPECT_FALSE(json["ugc"]["online"].get<bool>());
|
||||
EXPECT_FALSE(json["ugc"]["enabled"].get<bool>());
|
||||
EXPECT_TRUE(json["worlds"].empty());
|
||||
EXPECT_EQ(json["stats"]["onlinePlayers"].get<uint32_t>(), 0);
|
||||
}
|
||||
@@ -165,3 +172,25 @@ TEST_F(ServerStateTest, ServerStatusDefaults) {
|
||||
EXPECT_EQ(status.players, 0);
|
||||
EXPECT_EQ(status.version, "");
|
||||
}
|
||||
|
||||
TEST_F(ServerStateTest, UgcServerComesAndGoes) {
|
||||
{
|
||||
std::lock_guard lock(ServerState::g_StatusMutex);
|
||||
ServerState::g_UgcEnabled = true;
|
||||
ServerState::g_UgcStatus.Set(true);
|
||||
}
|
||||
auto json = ServerState::GetServerStateJson();
|
||||
EXPECT_TRUE(json["ugc"]["enabled"].get<bool>());
|
||||
EXPECT_TRUE(json["ugc"]["online"].get<bool>());
|
||||
const auto since = json["ugc"]["since"].get<int64_t>();
|
||||
EXPECT_GT(since, 0);
|
||||
|
||||
// Still up: it keeps the time it came up
|
||||
ServerState::g_UgcStatus.Set(true);
|
||||
EXPECT_EQ(ServerState::GetServerStateJson()["ugc"]["since"].get<int64_t>(), since);
|
||||
|
||||
ServerState::g_UgcStatus.Set(false);
|
||||
json = ServerState::GetServerStateJson();
|
||||
EXPECT_FALSE(json["ugc"]["online"].get<bool>());
|
||||
EXPECT_EQ(json["ugc"]["since"].get<int64_t>(), 0);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user