mirror of
https://github.com/BeamMP/BeamMP-Server.git
synced 2026-07-13 10:13:42 +00:00
add connection limiter stats to status command
This commit is contained in:
@@ -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)) {
|
||||
|
||||
Reference in New Issue
Block a user