How Idle Detection Works
The idle monitor runs a periodic check loop:Monitor wakes up
Every
HATCH_IDLE_CHECK_INTERVAL (default: 5 minutes), the monitor checks all running VMs.Identify VMs with proxy routes
Only VMs that have at least one proxy route are evaluated. VMs without routes are ignored.
Calculate idle time
For each VM, the monitor checks:
- Last proxy request time: Tracked by the reverse proxy for each subdomain
- VM creation time: Used as baseline if no proxy requests have been made
- SSH connection status: Checks kernel conntrack for active SSH sessions
Compare against timeout
If idle time exceeds
HATCH_IDLE_TIMEOUT (default: 30 minutes) and no active SSH sessions exist, the VM is snapshotted.The idle monitor only affects VMs in
running state. Stopped, snapshotted, or errored VMs are ignored.Configuring Idle Timeout
Control idle detection behavior with environment variables:Idle Time Calculation
The idle monitor uses this logic to determine idle time:- VMs are considered active if they’ve received HTTP requests via the proxy
- VMs without any proxy requests are considered idle since creation
- Active SSH sessions prevent snapshotting (see below)
SSH Session Detection
Before snapshotting a VM, the idle monitor checks for active SSH connections:Query netfilter conntrack
The monitor reads
/proc/net/nf_conntrack to find established TCP connections.Auto-Snapshot Behavior
When the idle monitor triggers a snapshot:VM transitions to snapshotted
The VM state changes to
snapshotted, and the Firecracker process is terminated.error and remains running:
VMs Without Proxy Routes
VMs that do not have any proxy routes are never snapshotted by the idle monitor, regardless of activity level. Rationale:- VMs without routes are not exposed via HTTP, so proxy traffic is not a meaningful activity indicator
- Such VMs may be used for batch processing, databases, or SSH-only access
- Users must manually snapshot these VMs if desired
To enable idle management for a VM, create at least one proxy route, even if you don’t plan to use it for HTTP traffic.
Monitoring Idle VMs
You can identify VMs that are idle by querying the API:Wake-on-Request
When an idle-snapshotted VM receives an HTTP request via a proxy route withauto_wake: true, it automatically restores:
Disabling Idle Management
To prevent a specific VM from being idle-snapshotted:Option 1: Don’t create proxy routes
VMs without proxy routes are never evaluated by the idle monitor.Option 2: Set a very long idle timeout
Option 3: Keep VMs active
Make periodic requests to the VM’s proxy route:Best Practices
Enable idle management for dev/staging
Save costs by letting non-production VMs snapshot when inactive:
Disable for production VMs
Keep production services always running:Or don’t create proxy routes for production VMs.
Use auto-wake with idle management
Enable auto-wake on proxy routes so snapshotted VMs wake on demand:
Monitor S3 snapshot storage
Idle snapshots consume S3 storage. Periodically review and clean up old snapshots.
Idle Monitor Logs
The idle monitor logs useful information: Startup:Troubleshooting
VM not being snapshotted
Possible causes:- VM has no proxy routes
- VM has active SSH session
- Idle time hasn’t exceeded timeout
- Idle monitor is not running
VM snapshotted too aggressively
Possible causes:- Idle timeout is too short
- Health check endpoint not being polled
- SSH detection not working (container networking issues)
Idle snapshots failing
Error:snapshot storage not configured
Solution: Configure S3 storage:
Advanced: SSH Detection Internals
The idle monitor detects SSH sessions by parsing/proc/net/nf_conntrack:
Sample conntrack entry:
- Filter lines containing
ESTABLISHED - Filter lines containing
dport={ssh_port}(e.g.,dport=2200) - If any matches found, SSH session is active
This detection method requires the host kernel to have
nf_conntrack enabled (standard on most Linux distributions).Configuration Reference
| Variable | Default | Description |
|---|---|---|
HATCH_IDLE_CHECK_INTERVAL | 5m | How often to check for idle VMs |
HATCH_IDLE_TIMEOUT | 30m | Idle duration before snapshotting |
HATCH_PROXY_WAKE_TIMEOUT | 30s | Max time to wait for restore during auto-wake |
30s= 30 seconds5m= 5 minutes2h= 2 hours24h= 24 hours
Next Steps
Reverse Proxy
Configure auto-wake for snapshotted VMs
Snapshots
Understand snapshot creation and restoration
Creating VMs
Learn about VM lifecycle and states
Network Setup
Configure SSH access and port forwarding