mirror of
https://github.com/BeamMP/BeamMP-Server.git
synced 2026-07-12 17:54:04 +00:00
add connection limiter stats to status command
This commit is contained in:
@@ -8,6 +8,15 @@
|
||||
|
||||
class TConnectionLimiter {
|
||||
public:
|
||||
struct TStats {
|
||||
size_t CurrentGlobal = 0;
|
||||
size_t MaxGlobal = 0;
|
||||
size_t ActiveIpBuckets = 0;
|
||||
size_t CurrentMaxPerIp = 0;
|
||||
size_t MaxPerIp = 0;
|
||||
size_t SaturatedIpBuckets = 0;
|
||||
};
|
||||
|
||||
class TGuard {
|
||||
public:
|
||||
TGuard() = default;
|
||||
@@ -36,6 +45,7 @@ public:
|
||||
TConnectionLimiter(size_t maxPerIp, size_t maxGlobal);
|
||||
|
||||
[[nodiscard]] std::optional<TGuard> TryAcquire(const std::string& ip);
|
||||
[[nodiscard]] TStats GetStats();
|
||||
|
||||
private:
|
||||
void Release(const std::string& ip) {
|
||||
|
||||
@@ -48,6 +48,7 @@ public:
|
||||
void SendToAll(TClient* c, const std::vector<uint8_t>& Data, bool Self, bool Rel);
|
||||
void UpdatePlayer(TClient& Client);
|
||||
boost::system::error_code ReadWithTimeout(TConnection& Connection, void* Buf, size_t Len, std::chrono::steady_clock::duration Timeout);
|
||||
[[nodiscard]] TConnectionLimiter::TStats GetConnectionLimiterStats() { return mConnectionLimiter.GetStats(); }
|
||||
|
||||
TResourceManager& ResourceManager() const { return mResourceManager; }
|
||||
|
||||
|
||||
@@ -32,6 +32,24 @@ std::optional<TConnectionLimiter::TGuard> TConnectionLimiter::TryAcquire(const s
|
||||
return TGuard(this, ip);
|
||||
}
|
||||
|
||||
TConnectionLimiter::TStats TConnectionLimiter::GetStats() {
|
||||
std::unique_lock Lock { mMutex };
|
||||
TStats Stats;
|
||||
Stats.CurrentGlobal = mGlobal;
|
||||
Stats.MaxGlobal = mMaxGlobal;
|
||||
Stats.ActiveIpBuckets = mPerIp.size();
|
||||
Stats.MaxPerIp = mMaxPerIp;
|
||||
for (const auto& [_, Count] : mPerIp) {
|
||||
if (Count > Stats.CurrentMaxPerIp) {
|
||||
Stats.CurrentMaxPerIp = Count;
|
||||
}
|
||||
if (Count >= mMaxPerIp) {
|
||||
++Stats.SaturatedIpBuckets;
|
||||
}
|
||||
}
|
||||
return Stats;
|
||||
}
|
||||
|
||||
TConnectionLimiter::TGuard::TGuard(TConnectionLimiter* owner, std::string ip)
|
||||
: mOwner(owner)
|
||||
, mIp(std::move(ip)) {
|
||||
|
||||
@@ -653,6 +653,7 @@ void TConsole::Command_Status(const std::string&, const std::vector<std::string>
|
||||
SystemsShutdownList = SystemsShutdownList.substr(0, SystemsShutdownList.size() - 2);
|
||||
|
||||
auto ElapsedTime = mLuaEngine->Server().UptimeTimer.GetElapsedTime();
|
||||
auto ConnectionLimiterStats = mLuaEngine->Network().GetConnectionLimiterStats();
|
||||
|
||||
Status << "BeamMP-Server Status:\n"
|
||||
<< "\tTotal Players: " << mLuaEngine->Server().ClientCount() << "\n"
|
||||
@@ -667,6 +668,11 @@ void TConsole::Command_Status(const std::string&, const std::vector<std::string>
|
||||
<< "\t\tStates: " << mLuaEngine->GetLuaStateCount() << "\n"
|
||||
<< "\t\tEvent timers: " << mLuaEngine->GetTimedEventsCount() << "\n"
|
||||
<< "\t\tEvent handlers: " << mLuaEngine->GetRegisteredEventHandlerCount() << "\n"
|
||||
<< "\tConnection limiter:\n"
|
||||
<< "\t\tActive/Max global: " << ConnectionLimiterStats.CurrentGlobal << "/" << ConnectionLimiterStats.MaxGlobal << "\n"
|
||||
<< "\t\tActive IP buckets: " << ConnectionLimiterStats.ActiveIpBuckets << "\n"
|
||||
<< "\t\tHighest single IP load: " << ConnectionLimiterStats.CurrentMaxPerIp << "/" << ConnectionLimiterStats.MaxPerIp << "\n"
|
||||
<< "\t\tSaturated IP buckets: " << ConnectionLimiterStats.SaturatedIpBuckets << "\n"
|
||||
<< "\tSubsystems:\n"
|
||||
<< "\t\tGood/Starting/Bad: " << SystemsGood << "/" << SystemsStarting << "/" << SystemsBad << "\n"
|
||||
<< "\t\tShutting down/Shut down: " << SystemsShuttingDown << "/" << SystemsShutdown << "\n"
|
||||
|
||||
Reference in New Issue
Block a user