Azure Cost Optimization Skill
Analyze Azure subscriptions to identify cost savings through orphaned resource cleanup, rightsizing, and optimization recommendations based on actual usage data.
When to Use This Skill
Use this skill when the user asks to:
- Optimize Azure costs or reduce spending
- Analyze Azure subscription for cost savings
- Generate cost optimization report
- Find orphaned or unused resources
- Rightsize Azure VMs, containers, or services
- Identify where they're overspending in Azure
- Optimize Redis costs specifically - See Azure Redis Cost Optimization for Redis-specific analysis
Instructions
Follow these steps in conversation with the user:
Step 0: Validate Prerequisites
Before starting, verify these tools and permissions are available:
Required Tools:
- Azure CLI installed and authenticated (
az login)
- Azure CLI extensions:
costmanagement, resource-graph
- Azure Quick Review (azqr) installed - See Azure Quick Review for details
Required Permissions:
- Cost Management Reader role
- Monitoring Reader role
- Reader role on subscription/resource group
Verification commands:
az --version
az account show
az extension show --name costmanagement
azqr version
Step 1: Load Best Practices
Get Azure cost optimization best practices to inform recommendations:
mcp_azure_mcp_get_azure_bestpractices({
intent: "Get cost optimization best practices",
command: "get_bestpractices",
parameters: { resource: "cost-optimization", action: "all" }
})
Step 1.5: Redis-Specific Analysis (Conditional)
If the user specifically requests Redis cost optimization, use the specialized Redis skill:
๐ Reference: Azure Redis Cost Optimization
When to use Redis-specific analysis:
- User mentions "Redis", "Azure Cache for Redis", or "Azure Managed Redis"
- Focus is on Redis resource optimization, not general subscription analysis
- User wants Redis-specific recommendations (SKU downgrade, failed caches, etc.)
Key capabilities:
- Interactive subscription filtering (prefix, ID, or "all subscriptions")
- Redis-specific optimization rules (failed caches, oversized tiers, missing tags)
- Pre-built report templates for Redis cost analysis
- Uses
redis_list command
Report templates available:
Note: For general subscription-wide cost optimization (including Redis), continue with Step 2. For Redis-only focused analysis, follow the instructions in the Redis-specific reference document.
Step 1.6: Choose Analysis Scope (for Redis-specific analysis)
If performing Redis cost optimization, ask the user to select their analysis scope:
Prompt the user with these options:
- Specific Subscription ID - Analyze a single subscription
- Subscription Name - Use display name instead of ID
- Subscription Prefix - Analyze all subscriptions starting with a prefix (e.g., "CacheTeam")
- All My Subscriptions - Scan all accessible subscriptions
- Tenant-wide - Analyze entire organization
Wait for user response, then proceed to Step 2.
Step 1.7: AKS-Specific Analysis (Conditional)
If the user specifically requests AKS cost optimization, use the specialized AKS reference files:
When to use AKS-specific analysis:
- User mentions "AKS", "Kubernetes", "cluster", "node pool", "pod", or "kubectl"
- User wants to enable the AKS cost analysis add-on or namespace cost visibility
- User reports a cost spike, unusual cluster utilization, or wants budget alerts
Tool Selection:
- Prefer MCP first: Use
mcp_azure_mcp_aks for AKS operations (list clusters, get node pools, inspect configuration) โ it provides richer metadata and is consistent with AKS skill conventions in this repo
- Fall back to CLI: Use
az aks and kubectl only when the specific operation cannot be performed via the MCP surface
Reference files (load only what is needed for the request):
Note: For general subscription-wide cost optimization (including AKS resource groups), continue with Step 2. For AKS-focused analysis, follow the instructions in the relevant reference file above.
Step 1.8: Choose Analysis Scope (for AKS-specific analysis)
If performing AKS cost optimization, ask the user to select their analysis scope:
Prompt the user with these options:
- Specific Cluster Name - Analyze a single AKS cluster
- Resource Group - Analyze all clusters in a resource group
- Subscription ID - Analyze all clusters in a subscription
- All My Clusters - Scan all accessible clusters across subscriptions
Wait for user response before proceeding to Step 2.
Step 2: Run Azure Quick Review
Run azqr to find orphaned resources (immediate cost savings):
๐ Reference: Azure Quick Review - Detailed instructions for running azqr scans
extension_azqr({
subscription: "<SUBSCRIPTION_ID>",
"resource-group": "<RESOURCE_GROUP>"
})
What to look for in azqr results:
- Orphaned resources: unattached disks, unused NICs, idle NAT gateways
- Over-provisioned resources: excessive retention periods, oversized SKUs
- Missing cost tags: resources without proper cost allocation
Note: The Azure Quick Review reference document includes instructions for creating filter configurations, saving output to the output/ folder, and interpreting results for cost optimization.
Step 3: Discover Resources
For efficient cross-subscription resource discovery, use Azure Resource Graph. See Azure Resource Graph Queries for orphaned resource detection and cost optimization patterns.
List all resources in the subscription using Azure MCP tools or CLI:
az account show
az resource list --subscription "<SUBSCRIPTION_ID>" --resource-group "<RESOURCE_GROUP>"
Step 4: Query Actual Costs
Get actual cost data from Azure Cost Management API (last 30 days):
Create cost query file:
Create temp/cost-query.json with:
{
"type": "ActualCost",
"timeframe": "Custom",
"timePeriod": {
"from": "<START_DATE>",
"to": "<END_DATE>"
},
"dataset": {
"granularity": "None",
"aggregation": {
"totalCost": {
"name": "Cost",
"function": "Sum"
}
},
"grouping": [
{
"type": "Dimension",
"name": "ResourceId"
}
]
}
}
Action Required: Calculate <START_DATE> (30 days ago) and <END_DATE> (today) in ISO 8601 format (e.g., 2025-11-03T00:00:00Z).
Execute cost query:
New-Item -ItemType Directory -Path "temp" -Force
az rest --method post `
--url "https://management.azure.com/subscriptions/<SUBSCRIPTION_ID>/resourceGroups/<RESOURCE_GROUP>/providers/Microsoft.CostManagement/query?api-version=2023-11-01" `
--body '@temp/cost-query.json'
Important: Save the query results to output/cost-query-result<timestamp>.json for audit trail.
Step 5: Validate Pricing
Fetch current pricing from official Azure pricing pages using fetch_webpage:
fetch_webpage({
urls: ["https://azure.microsoft.com/en-us/pricing/details/container-apps/"],
query: "pricing tiers and costs"
})
Key services to validate:
Important: Check for free tier allowances - many Azure services have generous free limits that may explain $0 costs.
Step 6: Collect Utilization Metrics
Query Azure Monitor for utilization data (last 14 days) to support rightsizing recommendations:
$startTime = (Get-Date).AddDays(-14).ToString("yyyy-MM-ddTHH:mm:ssZ")
$endTime = Get-Date -Format "yyyy-MM-ddTHH:mm:ssZ"
az monitor metrics list `
--resource "<RESOURCE_ID>" `
--metric "Percentage CPU" `
--interval PT1H `
--aggregation Average `
--start-time $startTime `
--end-time $endTime
az monitor metrics list `
--resource "<RESOURCE_ID>" `
--metric "CpuTime,Requests" `
--interval PT1H `
--aggregation Total `
--start-time $startTime `
--end-time $endTime
az monitor metrics list `
--resource "<RESOURCE_ID>" `
--metric "UsedCapacity,BlobCount" `
--interval PT1H `
--aggregation Average `
--start-time $startTime `
--end-time $endTime
Step 7: Generate Optimization Report
Create a comprehensive cost optimization report in the output/