|
| 1 | +## Azure App Service Cost Optimization |
| 2 | + |
| 3 | +Reference guide for reducing App Service costs through plan rightsizing, idle slot cleanup, and dev/test pricing. |
| 4 | + |
| 5 | +## Cost Optimization Rules |
| 6 | + |
| 7 | +| Priority | Rule | Detection Logic | Recommendation | Avg Savings | |
| 8 | +|----------|------|----------------|----------------|-------------| |
| 9 | +| 🔴 Critical | Stopped App on Paid Plan | `state == 'Stopped'` AND `sku.tier != 'Free/Shared'` | Delete or move to Free tier (stopped apps still incur plan cost) | $50-500/mo | |
| 10 | +| 🔴 Critical | Empty App Service Plan | Plan has zero apps deployed | Delete the plan | $50-400/mo | |
| 11 | +| 🟠 High | Premium in Non-Production | `sku.tier in ['PremiumV2','PremiumV3']` AND `tags.environment in ['dev','test','staging']` | Downgrade to Basic or Standard | $100-600/mo | |
| 12 | +| 🟠 High | Idle Deployment Slots | Non-production slots with zero traffic for 14+ days | Delete unused slots (each slot = separate app instance cost) | $50-300/mo | |
| 13 | +| 🟠 High | Over-Provisioned Plan | CPU avg <20% AND memory avg <30% over 14 days | Scale down SKU or reduce instance count | $50-400/mo | |
| 14 | +| 🟡 Medium | No Auto-Scale Rules | Production plan with fixed instance count >2 | Add auto-scale rules to scale in during low traffic | $30-200/mo | |
| 15 | +| 🟡 Medium | Missing Dev/Test Pricing | Dev/test workloads on regular pricing | Enable Dev/Test pricing via subscription offer | 30-55% savings | |
| 16 | +| 🟡 Medium | Always On for Non-Production | `alwaysOn == true` on dev/test apps | Disable Always On (apps cold-start on first request) | Reduced idle cost | |
| 17 | +| 🟢 Low | Untagged App Service | Missing `environment`, `owner`, or `costCenter` tags | Apply tags for cost allocation | N/A | |
| 18 | +| 🟢 Low | Old Deployment Slots | Slots older than 90 days not used for blue-green | Review if still needed | Variable | |
| 19 | + |
| 20 | +## Plan Tier Decision Matrix |
| 21 | + |
| 22 | +| Workload | Recommended Tier | Key Features | |
| 23 | +|----------|-----------------|--------------| |
| 24 | +| Dev/test, prototypes | Free / Basic B1 | No SLA, limited scale | |
| 25 | +| Low-traffic production | Standard S1 | Auto-scale, slots, backups | |
| 26 | +| High-traffic production | Premium P1v3 | Better perf, more slots, VNET | |
| 27 | +| Isolated compliance | Isolated I1v2 | Private environment, max scale | |
| 28 | + |
| 29 | +## Resource Graph Queries |
| 30 | + |
| 31 | +**Find stopped apps on paid plans:** |
| 32 | + |
| 33 | +```kql |
| 34 | +Resources |
| 35 | +| where type =~ 'microsoft.web/sites' |
| 36 | +| where properties.state =~ 'Stopped' |
| 37 | +| where isnotempty(properties.serverFarmId) |
| 38 | +| project name, resourceGroup, kind, state=properties.state |
| 39 | +``` |
| 40 | + |
| 41 | +**Find empty App Service Plans:** |
| 42 | + |
| 43 | +```kql |
| 44 | +Resources |
| 45 | +| where type =~ 'microsoft.web/serverfarms' |
| 46 | +| where properties.numberOfSites == 0 |
| 47 | +| project name, resourceGroup, sku=sku.name, location |
| 48 | +``` |
| 49 | + |
| 50 | +**Find Premium plans in non-production:** |
| 51 | + |
| 52 | +```kql |
| 53 | +Resources |
| 54 | +| where type =~ 'microsoft.web/serverfarms' |
| 55 | +| where sku.tier in~ ('PremiumV2', 'PremiumV3', 'Premium') |
| 56 | +| where tags.environment in~ ('dev', 'test', 'staging', 'sandbox') |
| 57 | +| project name, resourceGroup, sku=sku.name, tier=sku.tier, tags |
| 58 | +``` |
| 59 | + |
| 60 | +## Tools & Commands |
| 61 | + |
| 62 | +**MCP Tool:** `azure__appservice` for listing and managing App Service resources |
| 63 | + |
| 64 | +**Azure CLI:** |
| 65 | +- `az appservice plan list --resource-group <rg>` - List plans |
| 66 | +- `az appservice plan show --name <plan> --resource-group <rg>` - Plan details |
| 67 | +- `az webapp list --resource-group <rg>` - List web apps |
| 68 | +- `az webapp show --name <app> --resource-group <rg>` - App details |
| 69 | +- `az webapp deployment slot list --name <app> --resource-group <rg>` - List slots |
| 70 | +- `az monitor metrics list --resource <plan-id> --metric CpuPercentage --interval PT1H` - CPU utilization |
| 71 | +- `az monitor metrics list --resource <plan-id> --metric MemoryPercentage --interval PT1H` - Memory utilization |
| 72 | + |
| 73 | +## Pricing Quick Reference |
| 74 | + |
| 75 | +Approximate monthly costs (Linux, East US): |
| 76 | +- **Free F1**: $0 (60 min CPU/day, 1 GB RAM) |
| 77 | +- **Basic B1**: ~$13/mo (1 core, 1.75 GB) |
| 78 | +- **Standard S1**: ~$69/mo (1 core, 1.75 GB, auto-scale, slots) |
| 79 | +- **Premium P1v3**: ~$138/mo (2 cores, 8 GB, better perf) |
| 80 | + |
| 81 | +Each deployment slot runs as a separate instance at full plan cost. Windows plans cost ~30% more than Linux. |
| 82 | + |
| 83 | +Always validate from [official pricing](https://azure.microsoft.com/pricing/details/app-service/). |
0 commit comments