Az cost optimize

From mouadja02/skills · View interactive version

Az cost optimize is an AI agent skill from the GitHub repository mouadja02/skills. Analyze Azure resources used in the app (IaC files and/or resources in a target rg) and optimize costs - creating GitHub issues for identified optimizations. Use when an Azure bill needs reducing or a resource group needs a cost review.

How to use this skill

Skill file

Attribution: Sourced from github/awesome-copilot by GitHub Community, licensed MIT. Modified for this collection.

Azure Cost Optimize

This workflow analyzes Infrastructure-as-Code (IaC) files and Azure resources to generate cost optimization recommendations. It creates individual GitHub issues for each optimization opportunity plus one EPIC issue to coordinate implementation, enabling efficient tracking and execution of cost savings initiatives.

Prerequisites

Workflow Steps

Step 1: Get Azure Best Practices

Action: Retrieve cost optimization best practices before analysis

Tools: Azure MCP best practices tool

Process:

  1. Load Best Practices:

Step 2: Discover Azure Infrastructure

Action: Dynamically discover and analyze Azure resources and configurations

Tools: Azure MCP tools + Azure CLI fallback + Local file system access

Process:

  1. Resource Discovery:
  1. IaC Detection:
  1. Configuration Analysis:

Step 3: Collect Usage Metrics & Validate Current Costs

Action: Gather utilization data AND verify actual resource costs

Tools: Azure MCP monitoring tools + Azure CLI

Process:

  1. Find Monitoring Sources:
  1. Execute Usage Queries:

```kql

// CPU utilization for App Services

AppServiceAppLogs

| where TimeGenerated > ago(7d)

| summarize avg(CpuTime) by Resource, bin(TimeGenerated, 1h)

// Cosmos DB RU consumption

AzureDiagnostics

| where ResourceProvider == "MICROSOFT.DOCUMENTDB"

| where TimeGenerated > ago(7d)

| summarize avg(RequestCharge) by Resource

// Storage account access patterns

StorageBlobLogs

| where TimeGenerated > ago(7d)

| summarize RequestCount=count() by AccountName, bin(TimeGenerated, 1d)

```

  1. Calculate Baseline Metrics:
  1. VALIDATE CURRENT COSTS:

Step 4: Generate Cost Optimization Recommendations

Action: Analyze resources to identify optimization opportunities

Tools: Local analysis using collected data

Process:

  1. Apply Optimization Patterns based on resource types found:

Compute Optimizations:

Database Optimizations:

Storage Optimizations:

Infrastructure Optimizations:

  1. Calculate Evidence-Based Savings:
  1. Calculate Priority Score for each recommendation:

```

Priority Score = (Value Score × Monthly Savings) / (Risk Score × Implementation Days)

High Priority: Score > 20

Medium Priority: Score 5-20

Low Priority: Score < 5

```

  1. Validate Recommendations:

Step 5: User Confirmation

Action: Present summary and get approval before creating GitHub issues

Process:

  1. Display Optimization Summary:

```

🎯 Azure Cost Optimization Summary

📊 Analysis Results:

• Total Resources Analyzed: X

• Current Monthly Cost: $X

• Potential Monthly Savings: $Y

• Optimization Opportunities: Z

• High Priority Items: N

🏆 Recommendations:

1. [Resource]: [Current SKU] → [Target SKU] = $X/month savings - [Risk Level] | [Implementation Effort]

2. [Resource]: [Current Config] → [Target Config] = $Y/month savings - [Risk Level] | [Implementation Effort]

3. [Resource]: [Current Config] → [Target Config] = $Z/month savings - [Risk Level] | [Implementation Effort]

... and so on

💡 This will create:

• Y individual GitHub issues (one per optimization)

• 1 EPIC issue to coordinate implementation

❓ Proceed with creating GitHub issues? (y/n)

```

  1. Wait for User Confirmation: Only proceed if user confirms

Step 6: Create Individual Optimization Issues

Action: Create separate GitHub issues for each optimization opportunity. Label them with "cost-optimization" (green color), "azure" (blue color).

MCP Tools Required: create_issue for each recommendation

Process:

  1. Create Individual Issues using this template:

Title Format: [COST-OPT] [Resource Type] - [Brief Description] - $X/month savings

Body Template:

```markdown

## 💰 Cost Optimization: [Brief Title]

Monthly Savings: $X | Risk Level: [Low/Medium/High] | Implementation Effort: X days

### 📋 Description

[Clear explanation of the optimization and why it's needed]

### 🔧 Implementation

IaC Files Detected: [Yes/No - based on file_search results]

```bash

# If IaC files found: Show IaC modifications + deployment

# File: infrastructure/bicep/modules/app-service.bicep

# Change: sku.name: 'S3' → 'B2'

az deployment group create --resource-group [rg] --template-file infrastructure/bicep/main.bicep

# If no IaC files: Direct Azure CLI commands + warning

# ⚠️ No IaC files found. If they exist elsewhere, modify those instead.

az appservice plan update --name [plan] --sku B2

```

### 📊 Evidence

### ✅ Validation Steps

### ⚠️ Risks & Considerations

Priority Score: X | Value: X/10 | Risk: X/10

```

Step 7: Create EPIC Coordinating Issue

Action: Create master issue to track all optimization work. Label it with "cost-optimization" (green color), "azure" (blue color), and "epic" (purple color).

MCP Tools Required: create_issue for EPIC

Note about mermaid diagrams: Ensure you verify mermaid syntax is correct and create the diagrams taking accessibility guidelines into account (styling, colors, etc.).

Process:

  1. Create EPIC Issue:

Title: [EPIC] Azure Cost Optimization Initiative - $X/month potential savings

Body Template:

```markdown

# 🎯 Azure Cost Optimization EPIC

Total Potential Savings: $X/month | Implementation Timeline: X weeks

## 📊 Executive Summary

## 🏗️ Current Architecture Overview

```mermaid

graph TB

subgraph "Resource Group: [name]"

[Generated architecture diagram showing current resources and costs]

end

```

## 📋 Implementation Tracking

### 🚀 High Priority (Implement First)

### ⚡ Medium Priority

### 🔄 Low Priority (Nice to Have)

## 📈 Progress Tracking

## 🎯 Success Criteria

## 📝 Notes

```

Error Handling

Success Criteria

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.