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 gives you a structured, typed snapshot of a Pterodactyl server’s live resource usage at a single point in time — or as a smoothed average over a configurable sampling window. Rather than making multiple individual API calls and wiring the results together yourself, you instantiate Snapshot and immediately get snap.ram, snap.cpu, snap.tps, and other attributes populated and ready to use. This makes it straightforward to log resource metrics before and after a restart, gate actions on resource thresholds, or build monitoring loops that report averaged utilization under variable load.
Constructor
Any HungerLib server object.
GenericServer instances populate ram, cpu, network_in, network_out, and uptime. MinecraftServer instances additionally populate tps and players if they expose getTPS() and getPlayers() methods.Number of decimal places to round float metrics to. Applied to
ram, cpu, network_in, and network_out. Has no effect on tps, players, or uptime.Total seconds over which to collect samples for smoothing. When
duration=0.0 (the default), a single instant snapshot is taken. When duration > 0, the constructor blocks for the specified duration, collecting one sample every interval seconds, then sets each attribute to the mean of all collected samples.Seconds to sleep between consecutive samples when
duration > 0. Smaller values produce more samples (smoother averages) at the cost of more API calls to the Pterodactyl panel.Number of highest and lowest samples to discard from each metric before computing the mean. For example,
drop_outliers=1 removes the single highest and single lowest sample. Requires enough samples to have values remaining after dropping — ensure duration / interval > 2 * drop_outliers.When
True, RAM and network values are returned in gigabytes instead of megabytes. Pass gb=True for servers with large memory allocations where MB figures are unwieldy.Attributes
After construction, the following attributes are set on theSnapshot instance:
| Attribute | Type | Notes |
|---|---|---|
ram | float | Current RAM usage. Unit depends on gb flag (MB by default). |
cpu | float | CPU utilization percentage. |
network_in | float | Inbound network traffic. Unit depends on gb flag. |
network_out | float | Outbound network traffic. Unit depends on gb flag. |
tps | float | None | Ticks per second. Set only if Server has a getTPS() method (e.g. MinecraftServer). None otherwise. |
players | int | None | Online player count. Set only if Server has a getPlayers() method. None otherwise. |
uptime | int | Server uptime in seconds. Always an instant reading — not smoothed even when duration > 0. |
uptime_formatted | str | Human-readable uptime string (e.g. "2h 14m 08s"). |
When
duration > 0, tps and players are included in smoothing if the server supports them. When they are not supported, the corresponding lists remain empty and the attributes are set to None.Instant Snapshot
An instant snapshot makes a single API call per metric and returns immediately. Use this when you need current values without any latency budget.print(snap) outputs a multi-line summary using the __str__ implementation:
Smoothed Snapshot
Whenduration > 0, the constructor blocks and collects samples at interval-second intervals, then sets each attribute to the mean of all collected samples. This reduces the effect of momentary CPU or memory spikes on your readings.
duration=5.0 and interval=0.5, this collects 10 samples. drop_outliers=1 removes the highest and lowest reading from each metric before averaging, leaving 8 samples in the mean — a reliable baseline for alerting or logging.
Minecraft-Specific Metrics
MinecraftServer instances expose getTPS() and getPlayers() which Snapshot detects automatically using hasattr. TPS (ticks per second) and player count are populated in both instant and smoothed modes.
Using GB Instead of MB
For servers with large memory allocations, switch to gigabyte reporting withgb=True:
Comparing Before and After a Restart
Snapshot is particularly useful for capturing resource state on either side of a maintenance event:
str Reference
Snapshot.__str__() always includes the base fields. Minecraft-only fields are appended only when present: