Cost Calculations Guide
Deep dive into how FinFocus Core calculates projected and actual infrastructure costs.
Table of Contents
Section titled “Table of Contents”- Overview
- Projected Cost Calculations
- Actual Cost Calculations
- Cost Methodologies
- Data Sources
- Aggregation and Grouping
- Accuracy and Limitations
- Best Practices
Overview
Section titled “Overview”FinFocus Core provides two types of cost analysis:
- Projected Costs: Estimates based on resource specifications and pricing data
- Actual Costs: Historical spending retrieved from cloud provider APIs
Understanding how these calculations work helps you interpret results and optimize your infrastructure costs.
Projected Cost Calculations
Section titled “Projected Cost Calculations”Projected costs estimate monthly spending based on resource configurations and pricing specifications.
Calculation Flow
Section titled “Calculation Flow”graph TD A[Pulumi Plan JSON] --> B[Resource Extraction] B --> C[Resource Classification] C --> D{Plugin Available?} D -->|Yes| E[Plugin Pricing Query] D -->|No| F[Local Spec Lookup] E --> G[Cost Calculation] F --> G G --> H[Monthly Projection] H --> I[Result Aggregation]Resource Classification
Section titled “Resource Classification”Resources are classified by type and provider:
{ "type": "aws:ec2/instance:Instance", "provider": "aws", "service": "ec2", "resourceType": "instance"}Pricing Sources (Priority Order)
Section titled “Pricing Sources (Priority Order)”- Plugin Data: Live pricing from cloud provider APIs
- Local Specs: YAML/JSON pricing specifications
- Fallback Estimates: Default values by resource category
Monthly Calculation Formula
Section titled “Monthly Calculation Formula”Monthly Cost = Hourly Rate × Hours Per Month (730)Constants used:
- Hours per month: 730 (average accounting for varying month lengths)
- Hours per day: 24
- Days per month: 30.42 (average)
Example Calculation
Section titled “Example Calculation”AWS EC2 t3.micro instance:
# Pricing specpricing: onDemandHourly: 0.0104
# CalculationMonthly Cost = 0.0104 × 730 = $7.59Resource-Specific Calculations
Section titled “Resource-Specific Calculations”Compute Resources
Section titled “Compute Resources”- EC2 Instances: Based on instance type, region, and pricing model
- ECS Tasks: vCPU and memory allocation with Fargate pricing
- Lambda Functions: Execution time and memory allocation
Storage Resources
Section titled “Storage Resources”- S3 Buckets: Storage class, region, and estimated data volume
- EBS Volumes: Volume type, size, and IOPS provisioning
- EFS File Systems: Storage class and throughput mode
Database Resources
Section titled “Database Resources”- RDS Instances: Engine type, instance class, and storage
- DynamoDB Tables: Provisioned vs on-demand, read/write capacity
- DocumentDB Clusters: Instance type and storage requirements
Network Resources
Section titled “Network Resources”- Load Balancers: Type (ALB/NLB/CLB) and estimated data transfer
- NAT Gateways: Data processing charges
- VPC Endpoints: Interface vs Gateway endpoints
Fallback Pricing
Section titled “Fallback Pricing”When specific pricing is unavailable, default estimates are used:
const ( defaultDatabaseMonthlyCost = 50.0 // Database resources defaultStorageMonthlyCost = 5.0 // Storage resources defaultComputeMonthlyCost = 20.0 // Compute resources)Actual Cost Calculations
Section titled “Actual Cost Calculations”Actual costs retrieve historical spending data from cloud provider billing APIs through plugins.
Data Retrieval Flow
Section titled “Data Retrieval Flow”graph TD A[Date Range Request] --> B[Plugin Selection] B --> C[API Authentication] C --> D[Cost Data Query] D --> E[Resource Matching] E --> F[Data Aggregation] F --> G[Time Series Processing] G --> H[Result Formatting]Time Range Processing
Section titled “Time Range Processing”Date Format Support
Section titled “Date Format Support”- Simple dates:
2025-01-01(assumes start/end of day) - RFC3339:
2025-01-01T14:30:00Z(precise timestamps) - Partial timestamps:
2025-01-01T14:30:00Z(timezone aware)
Time Zone Handling
Section titled “Time Zone Handling”- All times converted to UTC for consistency
- Plugin APIs may return data in different time zones
- Results always include timezone information
Resource Matching
Section titled “Resource Matching”Resources from Pulumi plans are matched to cost data using:
- Resource ARN/ID: Direct matching where available
- Resource Tags: Tag-based identification
- Resource Type: Service and type matching
- Fuzzy Matching: Heuristic matching based on properties
Aggregation Methods
Section titled “Aggregation Methods”By Time Period
Section titled “By Time Period”{ "dailyCosts": [12.45, 13.67, 11.23, ...], "totalCost": 156.78, "costPeriod": "2025-01-01 to 2025-01-31"}By Resource
Section titled “By Resource”{ "resourceType": "aws:ec2/instance:Instance", "resourceId": "web-server", "totalCost": 89.45}By Service/Provider
Section titled “By Service/Provider”{ "summary": { "byProvider": { "aws": 156.78 }, "byService": { "ec2": 89.45, "s3": 23.12, "rds": 44.21 } }}Cost Methodologies
Section titled “Cost Methodologies”Projected vs Actual Cost Differences
Section titled “Projected vs Actual Cost Differences”| Aspect | Projected Costs | Actual Costs |
|---|---|---|
| Data Source | Pricing specifications | Billing APIs |
| Timing | Pre-deployment | Post-deployment |
| Accuracy | Estimates | Actual spending |
| Variability | Static pricing | Usage-based fluctuations |
| Scope | Resource configurations | Realized consumption |
Common Discrepancies
Section titled “Common Discrepancies”Usage Patterns
Section titled “Usage Patterns”- Projected: Assumes 100% uptime (730 hours/month)
- Actual: Reflects real usage patterns, scaling, downtime
Pricing Models
Section titled “Pricing Models”- Projected: Often uses on-demand pricing
- Actual: Includes reserved instances, spot instances, savings plans
Additional Services
Section titled “Additional Services”- Projected: Only explicitly defined resources
- Actual: Includes data transfer, API calls, storage I/O
Accuracy Factors
Section titled “Accuracy Factors”High Accuracy Scenarios
Section titled “High Accuracy Scenarios”- Well-defined resource specifications
- Stable usage patterns
- On-demand pricing models
- Simple resource configurations
Lower Accuracy Scenarios
Section titled “Lower Accuracy Scenarios”- Auto-scaling configurations
- Complex data transfer patterns
- Reserved instance utilization
- Multi-service dependencies
Data Sources
Section titled “Data Sources”Plugin-Based Data Sources
Section titled “Plugin-Based Data Sources”Kubecost Plugin
Section titled “Kubecost Plugin”- Source: Kubecost API
- Coverage: Kubernetes workloads, container costs
- Granularity: Pod, namespace, cluster level
- Update Frequency: Near real-time
AWS Cost Explorer Plugin
Section titled “AWS Cost Explorer Plugin”- Source: AWS Cost Explorer API
- Coverage: All AWS services
- Granularity: Resource, service, account level
- Update Frequency: Daily (24-hour delay)
Cloud Provider Plugins
Section titled “Cloud Provider Plugins”- Azure Cost Management: Azure spending data
- GCP Cloud Billing: Google Cloud costs
- Multi-cloud: Aggregated cross-cloud costs
Local Pricing Specifications
Section titled “Local Pricing Specifications”Format Example
Section titled “Format Example”provider: awsservice: ec2sku: t3.microcurrency: USDpricing: instanceType: t3.micro onDemandHourly: 0.0104 reservedHourly: 0.0074 spotHourly: 0.0031 monthlyEstimate: 7.59metadata: region: us-west-2 operatingSystem: linux tenancy: shared vcpu: 2 memory: 1Spec Discovery
Section titled “Spec Discovery”- Check
~/.finfocus/specs/directory - Match by provider, service, and SKU
- Fallback to generic service pricing
- Use default estimates if no match found
Aggregation and Grouping
Section titled “Aggregation and Grouping”Grouping Options
Section titled “Grouping Options”By Resource (group-by resource)
Section titled “By Resource (group-by resource)”{ "resourceType": "aws:ec2/instance:Instance", "resourceId": "web-server-1", "totalCost": 45.67}By Type (group-by type)
Section titled “By Type (group-by type)”{ "groupKey": "aws:ec2/instance:Instance", "totalCost": 134.56, "resourceCount": 3}By Provider (group-by provider)
Section titled “By Provider (group-by provider)”{ "groupKey": "aws", "totalCost": 456.78, "services": ["ec2", "s3", "rds"]}By Date (group-by date)
Section titled “By Date (group-by date)”{ "date": "2025-01-15", "totalCost": 15.67, "resources": [...]}By Tags (group-by tag:key=value)
Section titled “By Tags (group-by tag:key=value)”{ "tagKey": "Environment", "tagValue": "production", "totalCost": 234.56, "matchedResources": 12}Summary Calculations
Section titled “Summary Calculations”Cost Summary Structure
Section titled “Cost Summary Structure”{ "summary": { "totalMonthly": 456.78, "totalHourly": 0.626, "currency": "USD", "byProvider": { "aws": 456.78 }, "byService": { "ec2": 234.56, "s3": 78.9, "rds": 143.32 }, "byAdapter": { "kubecost": 234.56, "aws-spec": 222.22 } }}Aggregation Rules
Section titled “Aggregation Rules”- Sum: Total costs across resources
- Average: For rate-based metrics
- Count: Number of resources in group
- Currency: Unified to single currency (USD default)
Accuracy and Limitations
Section titled “Accuracy and Limitations”Projected Cost Limitations
Section titled “Projected Cost Limitations”Pricing Data Freshness
Section titled “Pricing Data Freshness”- Local specs may be outdated
- Regional pricing variations
- Promotional pricing not reflected
Usage Assumptions
Section titled “Usage Assumptions”- Assumes consistent 24/7 operation
- No auto-scaling considerations
- Static resource configurations
Missing Costs
Section titled “Missing Costs”- Data transfer charges
- API request costs
- Third-party service integrations
Actual Cost Limitations
Section titled “Actual Cost Limitations”Data Lag
Section titled “Data Lag”- Billing APIs have 12-48 hour delays
- Real-time costs not available
- Processing time for complex queries
Attribution Challenges
Section titled “Attribution Challenges”- Resource tagging inconsistencies
- Shared resource costs
- Multi-account cost allocation
Plugin Dependencies
Section titled “Plugin Dependencies”- Requires plugin installation and configuration
- API rate limits and authentication
- Network connectivity requirements
Improving Accuracy
Section titled “Improving Accuracy”For Projected Costs
Section titled “For Projected Costs”- Keep specs updated: Regularly update pricing specifications
- Use plugins: Leverage live pricing APIs when available
- Include usage patterns: Account for auto-scaling and variable usage
- Regional awareness: Use region-specific pricing
For Actual Costs
Section titled “For Actual Costs”- Consistent tagging: Implement comprehensive resource tagging
- Regular reconciliation: Compare projected vs actual regularly
- Multiple data sources: Use multiple plugins for validation
- Time range considerations: Allow for billing data processing delays
Best Practices
Section titled “Best Practices”Cost Estimation Workflow
Section titled “Cost Estimation Workflow”- Generate Projections: Start with projected cost estimates
- Deploy and Monitor: Track actual costs post-deployment
- Compare and Analyze: Identify discrepancies and patterns
- Optimize and Iterate: Adjust resources based on findings
Tagging Strategy
Section titled “Tagging Strategy”Implement consistent tagging for accurate cost attribution:
// Example Pulumi resource with comprehensive tagsconst webServer = new aws.ec2.Instance('web-server', { instanceType: 't3.micro', tags: { Environment: 'production', Team: 'backend', Project: 'web-app', CostCenter: 'engineering', Application: 'api-server', Owner: 'team@company.com', },});Regular Validation
Section titled “Regular Validation”# Monthly cost validation workflowfinfocus cost projected --pulumi-json plan.json --output json > projected.jsonfinfocus cost actual --pulumi-json plan.json --from $(date -d '1 month ago' +%Y-%m-01) --output json > actual.json
# Compare resultsjq -r '.summary.totalMonthly' projected.jsonjq -r '.summary.totalMonthly' actual.jsonCost Optimization
Section titled “Cost Optimization”Identify High-Cost Resources
Section titled “Identify High-Cost Resources”# Find most expensive resourcesfinfocus cost actual --pulumi-json plan.json --from 2025-01-01 --output json | \ jq '.resources | sort_by(.totalCost) | reverse | .[0:5]'Track Cost Trends
Section titled “Track Cost Trends”# Generate daily cost trendfor day in {01..31}; do finfocus cost actual --pulumi-json plan.json --from 2025-01-$day --to 2025-01-$day --output json | \ jq -r "[\"2025-01-$day\", .summary.totalMonthly] | @csv"done > cost-trend.csvRelated Documentation
Section titled “Related Documentation”- User Guide - Complete usage instructions
- Plugin System - Plugin development and configuration
- Troubleshooting - Common issues and solutions
- Examples - Sample pricing specs and configurations