Resource Statistics
Stats Structure
Environment-level statistics:environment/stats.go:4-31
Resource Usage Structure
Server-level resource tracking:server/resources.go:14-28
Statistics Collection
Getting Server Stats
- Thread-safe access
- Automatic disk usage update
- Returns copy of resource data
server/resources.go:32-39
Updating Stats
server/resources.go:42-46
API Endpoints
Get Server Details
router/router_server.go:21-23
API Response Structure
server/server.go:373-389
Real-Time Monitoring
Websocket Stats Events
Stats are published to websockets when updated:stats
Frequency: Continuous during server operation
Source: Referenced in server/server.go:334
State Change Events
status- When server state changesstats- When server goes offline (reset to 0)
server/server.go:317-359
Resource Metrics
Memory Tracking
Memory Usage:- Calculated from container stats
- Includes all memory used by container
- Compared against configured limit
environment/stats.go:9-14
CPU Tracking
CPU Absolute:- Percentage of total system CPU used
- Not limited to server’s CPU allocation
- Can exceed 100% on multi-core systems
25.5- Using 25.5% of one CPU core150.0- Using 1.5 CPU cores fully400.0- Using 4 CPU cores fully
environment/stats.go:18
Network Tracking
Received Bytes:- Total bytes since container start
- Cumulative counters (not rates)
- Resets when container restarts
environment/stats.go:27-30
Disk Tracking
Disk Usage:- Cached value from filesystem
- Updated when
Proc()is called - Not real-time (for performance)
server/resources.go:36
Uptime Tracking
Uptime:environment/stats.go:24
Resource Reset
Reset on Stop
- Server stops
- Server crashes
- Container is destroyed
Disk- Persists across restartsState- Updated to offline stateMemoryLimit- Configuration value
server/resources.go:50-59
Performance Monitoring
Server State Tracking
ProcessOfflineState- Server stoppedProcessStartingState- Server startingProcessRunningState- Server runningProcessStoppingState- Server stopping
server/server.go:364-368
Atomic State Storage
- Thread-safe reads/writes
- No mutex needed for state checks
- Concurrent access safe
server/resources.go:21
Monitoring Best Practices
Reading Statistics
Good:Websocket Monitoring
Subscribe to stats events for real-time monitoring:Polling Interval
For API polling: Recommended:- 1-5 seconds for active monitoring
- 10-30 seconds for dashboards
- 60+ seconds for historical data
- Sub-second polling (use websockets)
- Polling stopped servers
- Excessive concurrent requests
Metric Visualization
Memory Usage
CPU Usage
Network Rate
Calculate network rate from deltas:Disk Usage
Uptime
Integration Examples
Prometheus Metrics
Convert Wings stats to Prometheus format:Grafana Dashboards
Query Wings API for metrics:Alert Thresholds
Example monitoring alerts:Troubleshooting
Stats Not Updating
Check:- Server is running (
state === "running") - Websocket connection is active
- No errors in Wings logs
- Container is healthy in Docker
Incorrect Memory Values
Reasons:- Container overhead included
- Shared memory counted
- Cache/buffers included
High CPU Values
Expected:- Values can exceed 100%
- Each core can contribute 100%
- 400% on 4-core system is normal
- Sustained over limit
- Server unresponsive
- Other processes affected
Network Counters Reset
Causes:- Container restart
- Server reinstall
- Network driver reload
- Counters are cumulative
- Reset on container recreation
