Cost Tracking
Teabar provides detailed cost tracking to help you understand resource consumption, allocate costs to teams, and optimize cloud spending across all your ephemeral environments.
Overview
Cost tracking in Teabar covers:
- Real-time cost monitoring - See current spend as it accumulates
- Historical analysis - Review past spending patterns
- Cost allocation - Attribute costs to projects, teams, or users
- Budget alerts - Get notified before exceeding limits
- Optimization recommendations - Identify cost-saving opportunities
Note
Costs are calculated based on actual resource usage and updated every 5 minutes.
Viewing Costs
CLI
# View current month's costs
teabar costs show
# View costs for a specific project
teabar costs show --project my-project
# View costs for a specific environment
teabar costs show --env my-feature-env
# View costs for a date range
teabar costs show --from "2024-01-01" --to "2024-01-31"
# Group by dimension
teabar costs show --group-by project
teabar costs show --group-by user
teabar costs show --group-by environment Example output:
Cost Summary: January 2024
Organization: acme-corp
Total Cost: $1,234.56
By Project:
frontend $456.78 (37%)
backend $389.12 (32%)
data-pipeline $245.67 (20%)
infrastructure $142.99 (11%)
By Resource Type:
Compute $678.90 (55%)
Storage $234.56 (19%)
Network $198.76 (16%)
Other $122.34 (10%)
Active Environments: 47
Average Cost/Environment: $26.27 Dashboard
Access the cost dashboard at https://app.teabar.dev/costs.
Features include:
- Interactive cost charts
- Drill-down by project, user, or resource
- Cost trend analysis
- Export to CSV/PDF
Cost Breakdown
By Resource Type
Teabar tracks costs across resource categories:
| Resource Type | Description | Billing Unit |
|---|---|---|
| Compute | CPU and memory usage | $/hour |
| Storage | Persistent volumes, snapshots | $/GB-month |
| Network | Data transfer, load balancers | $/GB |
| Database | Managed database instances | $/hour |
| Cache | Redis, Memcached instances | $/hour |
By Environment
# Detailed cost breakdown for an environment
teabar costs breakdown my-feature-env Output:
Environment: my-feature-env
Period: 2024-01-01 to 2024-01-31
Total Cost: $45.67
Resource Breakdown:
web (container)
CPU: 2 vCPU × 720 hours $28.80
Memory: 4 GB × 720 hours $11.52
postgres (database)
Instance: db.small × 720 hours $3.60
Storage: 10 GB $1.00
redis (cache)
Instance: cache.small × 720 hours $0.75
Network:
Ingress: 50 GB $0.00
Egress: 25 GB $2.25 Budget Management
Setting Budgets
Configure spending limits at different levels:
# Set monthly organization budget
teabar budget set --org acme-corp --monthly 5000
# Set daily spending limit
teabar budget set --org acme-corp --daily 200Budget Alerts
Configure alerts when approaching budget limits:
# teabar.yaml
budgets:
organization:
monthly: 5000
alerts:
- threshold: 50%
channels: [email:[email protected]]
- threshold: 80%
channels: [slack:#platform-costs]
- threshold: 100%
channels: [slack:#platform-costs, pagerduty:oncall]
action: notify # or 'block' to prevent new environments
projects:
frontend:
monthly: 1000
per_environment: 50
alerts:
- threshold: 90%
channels: [slack:#frontend-team] Budget Actions
When budgets are exceeded:
| Action | Behavior |
|---|---|
notify | Send alert, allow continued spending |
warn | Show warning in CLI/UI, allow spending |
block | Prevent new environment creation |
terminate | Stop non-essential environments |
# Configure budget action
teabar budget set --project frontend --monthly 1000 --on-exceed block Cost Allocation
Tags and Labels
Use tags to allocate costs to cost centers:
# Create environment with cost allocation tags
teabar env create my-feature-env
--tag team=platform
--tag cost-center=engineering
--tag [email protected] Cost Reports by Tag
# Generate cost report by tag
teabar costs report --group-by tag:team
# Export for accounting
teabar costs export --group-by tag:cost-center --format csv --output costs.csv Output:
Cost Report by Team
Period: January 2024
Team Environments Total Cost
platform 12 $456.78
frontend 8 $234.56
backend 15 $389.12
data 5 $154.10
-----------------------------------------
Total 40 $1,234.56 Cost Optimization
Recommendations
Teabar analyzes usage patterns and suggests optimizations:
# Get optimization recommendations
teabar costs optimize Output:
Cost Optimization Recommendations
1. [HIGH] Idle Environments
5 environments have been idle for >7 days
Potential savings: $125/month
Environments:
- test-env-old (idle 14 days)
- feature-abandoned (idle 21 days)
- demo-staging (idle 10 days)
Action: teabar env delete test-env-old feature-abandoned demo-staging
2. [MEDIUM] Oversized Resources
3 environments are using <20% of allocated resources
Potential savings: $89/month
Environments:
- api-staging: 4 vCPU allocated, 0.5 vCPU used
- worker-test: 8 GB RAM allocated, 1.2 GB used
Action: teabar env resize api-staging --cpu 1 --memory 2G
3. [LOW] Storage Cleanup
12 GB of orphaned volumes detected
Potential savings: $1.20/month
Action: teabar storage prune --orphaned Auto-Cleanup Policies
Configure automatic cleanup to reduce costs:
# teabar.yaml
cleanup:
# Delete environments after inactivity
idle_timeout: 7d
# Delete environments after max lifetime
max_lifetime: 30d
# Exclude specific environments
exclude:
- production
- staging
# Notify before deletion
notify_before: 24h
notify_channels:
- slack:#platform-alerts Resource Right-Sizing
# Analyze resource usage and suggest sizes
teabar env analyze my-feature-env
# Auto-resize based on usage
teabar env resize my-feature-env --auto
# Set resource limits to prevent over-provisioning
teabar project config set resource_limits.max_cpu 4
teabar project config set resource_limits.max_memory 8G Exporting Cost Data
CSV Export
# Export monthly costs to CSV
teabar costs export
--from "2024-01-01"
--to "2024-01-31"
--format csv
--output january-costs.csv API Access
# Get costs via API (use OIDC token from teabar auth or Keycloak service account)
curl -H "Authorization: Bearer $TEABAR_TOKEN"
"https://api.teabar.dev/v1/costs?from=2024-01-01&to=2024-01-31" Response:
{
"period": {
"from": "2024-01-01",
"to": "2024-01-31"
},
"total": 1234.56,
"currency": "USD",
"breakdown": {
"compute": 678.90,
"storage": 234.56,
"network": 198.76,
"other": 122.34
},
"by_project": [
{"project": "frontend", "cost": 456.78},
{"project": "backend", "cost": 389.12}
]
} Best Practices
- Set budgets proactively - Configure limits before costs become an issue
- Tag everything - Use consistent tags for cost allocation
- Review weekly - Check cost trends and recommendations regularly
- Enable auto-cleanup - Prevent idle environments from accumulating costs
- Right-size resources - Start small and scale up based on actual usage
- Use spot instances - For non-critical environments, enable spot pricing
Warning
Deleted environments still incur costs for any retained data (snapshots, logs) until those are also deleted.