Documentation Index
Fetch the complete documentation index at: https://mintlify.com/iFamishedX/HungerLib/llms.txt
Use this file to discover all available pages before exploring further.
Snapshot captures a point-in-time (or time-averaged) view of a server’s resource metrics into a plain Python object. Pass a GenericServer or MinecraftServer to the constructor and read off ram, cpu, network_in, network_out, uptime, and — for Minecraft servers — tps and players. When duration > 0, the constructor blocks while collecting multiple samples and returns their mean, optionally trimming outliers first.
Constructor
The server object to sample. Any object that implements
getRAM(), getCPU(), getNetworkIn(), getNetworkOut(), and getUptime() is accepted. If the object also exposes getTPS() and getPlayers() (i.e. a MinecraftServer), those metrics are captured too.Number of decimal places passed to
getRAM(), getNetworkIn(), and getNetworkOut(). Does not affect cpu, tps, or players.Total sampling window in seconds. When
0.0 (default), a single instantaneous reading is taken and the constructor returns immediately. When > 0, the constructor blocks and collects samples at interval-second intervals until duration seconds have elapsed, then averages the results.Delay in seconds between samples when
duration > 0. A value of 0.5 collects two samples per second. Has no effect when duration == 0.Number of extreme samples (lowest and highest) to remove per metric before computing the mean. For example,
drop_outliers=1 sorts the sample list, drops the single lowest and single highest value, then averages the remainder. Has no effect when duration == 0 or when there are not enough samples remaining after trimming.When
True, RAM and network metrics are collected in gigabytes. When False (default), they are collected in megabytes.Instance Attributes
After construction, the following attributes are available on the snapshot object. All floating-point values reflect therounding and gb settings passed to the constructor.
RAM usage in MB (or GB when
gb=True). None if the server did not report a value. For smoothed snapshots, this is the mean of all collected samples after outlier trimming.CPU usage as an absolute percentage (e.g.
45.67). None if unavailable. Mean for smoothed snapshots.Cumulative inbound network usage in MB or GB.
None if unavailable. Mean for smoothed snapshots.Cumulative outbound network usage in MB or GB.
None if unavailable. Mean for smoothed snapshots.Current TPS (ticks per second) from HungerBridge. Always set on the snapshot object.
None for GenericServer instances (which lack getTPS()), or if the bridge is unreachable. Mean for smoothed snapshots.Number of online players from HungerBridge. Always set on the snapshot object.
None for GenericServer instances (which lack getPlayers()). For smoothed snapshots, this is the mean of sampled counts (may be a float).Server uptime in seconds at the time of snapshot construction. Captured once — not smoothed even when
duration > 0.Human-readable uptime string, e.g.
"2h 15m", "45m 30s", or "12s". Captured once alongside uptime.Smoothing Behaviour
Whenduration > 0, the constructor enters a sampling loop:
- On each iteration it calls
getRAM(),getCPU(),getNetworkIn(),getNetworkOut(), and (if available)getTPS()andgetPlayers(). - It sleeps for
intervalseconds, then repeats untiltime.time()exceeds the start time plusduration. - After sampling, each metric’s list is sorted. If
drop_outliers > 0, theNlowest andNhighest values are removed. - The remaining values are averaged with
statistics.mean().
uptime and uptime_formatted are always captured exactly once at the end of the sampling window, not averaged.
__str__
Snapshot.__str__() returns a multi-line human-readable summary:
TPS and Online players lines are only included when those attributes are not None.
GenericServer vs MinecraftServer
| Attribute | GenericServer | MinecraftServer |
|---|---|---|
ram | ✅ | ✅ |
cpu | ✅ | ✅ |
network_in | ✅ | ✅ |
network_out | ✅ | ✅ |
uptime | ✅ | ✅ |
uptime_formatted | ✅ | ✅ |
tps | None | ✅ (requires HungerBridge) |
players | None | ✅ (requires HungerBridge) |