Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Analyze Azure subscriptions to find cost savings via orphaned resources, rightsizing, and usage data
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
cost-optimization/workflow.md
1# Cost Optimization Workflow23Use this workflow when the user wants to **reduce their costs** โ find waste, orphaned resources, rightsizing opportunities.45> **Important:** Always present the total bill and cost breakdown (from the [Cost Query Workflow](../cost-query/workflow.md)) alongside optimization recommendations.67## Step 0: Validate Prerequisites89**Required Tools:**10- Azure CLI installed and authenticated (`az login`)11- Azure CLI extensions: `costmanagement`, `resource-graph`12- Azure Quick Review (azqr) installed โ See [Azure Quick Review](./azure-quick-review.md)1314**Required Permissions:**15- Cost Management Reader role16- Monitoring Reader role17- Reader role on subscription/resource group1819**Verification commands:**20```powershell21az --version22az account show23az extension show --name costmanagement24azqr version25```2627## Step 1: Load Best Practices2829```javascript30azure__get_azure_bestpractices({31intent: "Get cost optimization best practices",32command: "get_bestpractices",33parameters: { resource: "cost-optimization", action: "all" }34})35```3637## Step 1.5: Redis-Specific Analysis (Conditional)3839**If the user specifically requests Redis cost optimization**, use the specialized Redis reference:4041**Reference**: [Azure Redis Cost Optimization](./services/redis/azure-cache-for-redis.md)4243**When to use:**44- User mentions "Redis", "Azure Cache for Redis", or "Azure Managed Redis"45- Focus is on Redis resource optimization, not general subscription analysis4647> ๐ก **Note:** For general subscription-wide optimization, continue with Step 2. For Redis-only analysis, follow the Redis reference document.4849## Step 1.6: Choose Analysis Scope (for Redis-specific analysis)5051**If performing Redis cost optimization**, ask the user to select:521. **Specific Subscription ID**532. **Subscription Name**543. **Subscription Prefix** (e.g., "CacheTeam")554. **All My Subscriptions**565. **Tenant-wide**5758Wait for user response before proceeding.5960## Step 1.7: Storage-Specific Analysis (Conditional)6162**If the user requests Storage cost optimization**, load: [Azure Storage Cost Optimization](./services/storage/azure-storage.md)6364**Triggers:** "storage account cost", "blob storage savings", "LRS/GRS/ZRS downgrade", "storage lifecycle savings", "reduce storage spending".6566For Storage-only requests, follow the Storage reference. For general optimization that includes storage, continue to Step 2.6768## Step 1.8: AKS-Specific Analysis (Conditional)6970**If the user specifically requests AKS cost optimization**, use the specialized AKS reference files:7172**When to use AKS-specific analysis:**73- User mentions "AKS", "Kubernetes", "cluster", "node pool", "pod", or "kubectl"74- User wants to enable the AKS cost analysis add-on or namespace cost visibility75- User reports a cost spike, unusual cluster utilization, or wants budget alerts7677**Tool Selection:**78- **Prefer MCP first**: Use `azure__aks` for AKS operations (list clusters, get node pools, inspect configuration) โ it provides richer metadata and is consistent with AKS skill conventions in this repo79- **Fall back to CLI**: Use `az aks` and `kubectl` only when the specific operation cannot be performed via the MCP surface8081**Reference files (load only what is needed for the request):**82- [Cost Analysis Add-on](./azure-aks-cost-addon.md) โ enable namespace-level cost visibility83- [Anomaly Investigation](./azure-aks-anomalies.md) โ cost spikes, scaling events, budget alerts8485> **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.8687## Step 1.9: Choose Analysis Scope (for AKS-specific analysis)8889**If performing AKS cost optimization**, ask the user to select their analysis scope:9091**Prompt the user with these options:**921. **Specific Cluster Name** - Analyze a single AKS cluster932. **Resource Group** - Analyze all clusters in a resource group943. **Subscription ID** - Analyze all clusters in a subscription954. **All My Clusters** - Scan all accessible clusters across subscriptions9697Wait for user response before proceeding to Step 2.9899## Step 2: Run Azure Quick Review100101Run azqr to find orphaned resources (immediate cost savings):102103**Reference**: [Azure Quick Review](./azure-quick-review.md)104105```yaml106azure__extension_azqr107subscription: "<SUBSCRIPTION_ID>"108resource-group: "<RESOURCE_GROUP>" # optional109```110111**What to look for:**112- Orphaned resources: unattached disks, unused NICs, idle NAT gateways113- Over-provisioned resources: excessive retention periods, oversized SKUs114- Missing cost tags115116## Step 3: Discover Resources117118Use Azure Resource Graph for efficient cross-subscription resource discovery. See [Azure Resource Graph Queries](./azure-resource-graph.md) for orphaned resource detection patterns.119120```powershell121az account show122az resource list --subscription "<SUBSCRIPTION_ID>" --resource-group "<RESOURCE_GROUP>"123```124125## Step 4: Query Actual Costs126127Get actual cost data from Azure Cost Management API (last 30 days). Use the [Cost Query Workflow](../cost-query/workflow.md) with this configuration:128129**Create `temp/cost-query.json`:**130```json131{132"type": "ActualCost",133"timeframe": "Custom",134"timePeriod": {135"from": "<START_DATE>",136"to": "<END_DATE>"137},138"dataset": {139"granularity": "None",140"aggregation": {141"totalCost": {142"name": "Cost",143"function": "Sum"144}145},146"grouping": [147{148"type": "Dimension",149"name": "ResourceId"150}151]152}153}154```155156> **Action Required**: Calculate `<START_DATE>` (30 days ago) and `<END_DATE>` (today) in ISO 8601 format.157158**Execute and save results to `output/cost-query-result<timestamp>.json`.** Always include the `--headers "ClientType=GitHubCopilotForAzure"` header in all Cost Management API requests.159160> ๐ก **Tip:** Also run a cost-by-service query (grouping by `ServiceName`) to present the total bill breakdown alongside optimization recommendations. See [examples.md](../cost-query/examples.md).161162> โ ๏ธ **Warning:** Sequential queries to the same scope share the per-scope rate limit (4 requests/minute). If a 429 response is received, check all `x-ms-ratelimit-microsoft.costmanagement-*-retry-after` headers and do not send further requests until the longest retry-after duration has elapsed.163164## Step 5: Validate Pricing165166Fetch current pricing from official Azure pricing pages using `fetch_webpage`:167168**Key services to validate:**169- Container Apps: https://azure.microsoft.com/pricing/details/container-apps/170- Virtual Machines: https://azure.microsoft.com/pricing/details/virtual-machines/171- App Service: https://azure.microsoft.com/pricing/details/app-service/172- Log Analytics: https://azure.microsoft.com/pricing/details/monitor/173174> **Important**: Check for free tier allowances โ many Azure services have generous free limits.175176## Step 6: Collect Utilization Metrics177178Query Azure Monitor for utilization data (last 14 days) to support rightsizing recommendations:179180```powershell181$startTime = (Get-Date).AddDays(-14).ToString("yyyy-MM-ddTHH:mm:ssZ")182$endTime = Get-Date -Format "yyyy-MM-ddTHH:mm:ssZ"183184# VM CPU utilization185az monitor metrics list `186--resource "<RESOURCE_ID>" `187--metric "Percentage CPU" `188--interval PT1H `189--aggregation Average `190--start-time $startTime `191--end-time $endTime192```193194## Step 7: Generate Optimization Report195196Generate a report to `output/costoptimizereport<YYYYMMDD_HHMMSS>.md` that includes an executive summary, cost breakdown by service, free tier analysis, orphaned resources, prioritized optimization recommendations, and implementation commands. Save cost query results to `output/cost-query-result<YYYYMMDD_HHMMSS>.json` for audit trail, then clean up temporary files.197198For the complete report template, see [report-template.md](./report-template.md).199