Overview
Lightd includes a comprehensive billing system that tracks resource usage and calculates costs for containers and volumes. The system monitors CPU, memory, storage, and network usage in real-time.Features
Real-time Monitoring
Tracks CPU, memory, storage, and network usage every 60 seconds
Flexible Billing Rates
Configurable per-resource pricing
Multiple Time Windows
Hourly, daily, and monthly cost estimates
Container-level Tracking
Per-container resource usage and costs
Volume-level Tracking
Storage costs for volumes
Async Collection
Non-blocking metrics gathering
Configuration
Enable billing monitoring inconfig.json:
enabled- Enable/disable billing monitoringinterval_ms- Collection interval in milliseconds (default: 60000 = 1 minute)memory_per_gb_hour- Cost per GB of memory per hourcpu_per_vcpu_hour- Cost per vCPU per hourstorage_per_gb_hour- Cost per GB of storage per houregress_per_gb- Cost per GB of network egress
Get Hourly Usage
Get hourly resource usage and costs for a container.Get Daily Usage
Get daily resource usage and costs for a container.Get Monthly Usage
Get monthly resource usage and costs for a container.Estimate Container Costs
Estimate costs for a container configuration before creation.Estimate Volume Costs
Estimate costs for a volume configuration.Monitoring System
The billing system runs asynchronously in the background:Cost Breakdown
Memory Costs
- Calculated per GB per hour
- Based on actual memory usage
- Formula:
memory_gb × memory_per_gb_hour × hours
CPU Costs
- Calculated per vCPU per hour
- Based on CPU usage percentage
- Formula:
cpu_vcpu × cpu_per_vcpu_hour × hours
Storage Costs
- Calculated per GB per hour
- Based on disk usage
- Formula:
storage_gb × storage_per_gb_hour × hours
Network Egress Costs
- Calculated per GB transferred
- One-time charge per GB
- Formula:
egress_gb × egress_per_gb
Complete Example
Best Practices
Monitor Regularly
Monitor Regularly
Check usage and costs regularly to avoid surprises. Set up automated alerts for high costs.
Estimate Before Creating
Estimate Before Creating
Always estimate costs before creating containers to ensure they fit within budget.
Optimize Resources
Optimize Resources
Right-size containers based on actual usage to minimize costs.
Track Trends
Track Trends
Monitor daily and monthly trends to identify cost optimization opportunities.
Set Budgets
Set Budgets
Implement budget alerts and automatic scaling based on cost thresholds.
Performance
- Non-blocking: Metrics collection runs asynchronously
- Efficient: Uses streaming Docker API
- Scalable: Handles any number of containers
- Low overhead: Minimal impact on container performance
Security
- All billing endpoints require authentication
- Usage data is isolated per container
- No sensitive data exposed in responses
- Audit trail of all cost queries