/*************************************************************************
* ModernUO *
* Copyright 2019-2026 - ModernUO Development Team *
* Email: hi@modernuo.com *
* File: NetworkStats.cs *
* *
* This program is free software: you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation, either version 3 of the License, or *
* (at your option) any later version. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see . *
*************************************************************************/
namespace Server.Network;
/// One send buffer growth tier's pool usage, in buffers of bytes.
/// Physical size of every buffer in this tier.
/// Buffers the tier's allocated slabs hold.
/// Buffers currently handed out.
/// Peak usage the retention window is still holding capacity for.
public readonly record struct SendBufferTierUsage(int BufferSize, int Capacity, int InUse, int RetainFloor);
///
/// What the last once-a-minute send buffer maintenance sweep saw. The refusal counts cover the
/// minute before that sweep only.
///
/// False until the first sweep; every other field is then meaningless.
/// when the sweep ran; compare by subtraction only.
/// Slab capacity allocated across the growth tiers.
/// Growth-tier buffers handed out, summed across tiers.
/// Retention floors summed across tiers, in buffers.
/// Growth-tier buffers the sweep returned to the OS.
/// Slab capacity allocated across the base and pre-auth pools.
/// Base and pre-auth buffers the sweep returned to the OS.
/// Growth refused because the tiers were at the growth budget.
/// Growth refused because the buffer was already at the maximum size.
/// Growth refused because the process was above the memory ceiling.
public readonly record struct SendBufferSweep(
bool Ran,
long Tick,
long TierCapacityBytes,
int TierInUse,
int TierRetainFloor,
int TierBuffersReleased,
long BaseCapacityBytes,
int BaseBuffersReleased,
int BudgetRefusals,
int CapRefusals,
int CeilingRefusals
);
///
/// Read-only snapshot of the network layer for diagnostics. Connection counts and tier usage are
/// live; everything under is up to a minute old. Cold path: allocates.
///
/// Sockets the transport currently holds, authenticated or not.
/// Socket slots the transport was built with.
/// Connections past login, and so holding full-size buffers.
/// Base receive buffer size.
/// Base send buffer size.
/// Largest size a send buffer can grow to.
/// Pre-auth receive buffer size; 0 when pre-auth buffers are off.
/// Pre-auth send buffer size; 0 when pre-auth buffers are off.
/// Bytes the growth tiers may hold in total.
/// Growth stops once the process exceeds this share of available memory.
/// Memory available to the process as of the last sweep.
/// Live usage of each growth tier, smallest first.
/// What the last maintenance sweep saw.
/// Connections whose parser is paused on a packet throttle.
/// Connections with unsent bytes queued for the next flush.
/// Connections closing after their final flush.
public readonly record struct NetworkStats(
int Connected,
int MaxConnections,
int Authenticated,
int RecvBufferSize,
int SendBufferSize,
int MaxSendBufferSize,
int InitialRecvBufferSize,
int InitialSendBufferSize,
long SendBufferGrowthBudget,
int MemoryCeilingPercent,
long AvailableMemoryBytes,
SendBufferTierUsage[] Tiers,
SendBufferSweep LastSweep,
int Throttled,
int FlushPending,
int PendingDisconnects
);