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:
Aaron Kimbrell
2026-09-27 09:23:16 -05:00
parent 63496f52ab
commit fe67b5635d
18 changed files with 349 additions and 64 deletions

View File

@@ -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);
}