Skip to content

Repository files navigation

Azure Cost Optimizer

A powerful CLI tool that analyzes Azure resources and identifies cost optimization opportunities. Provides actionable recommendations with projected savings across compute, storage, networking, and database services.

PyPI Python CI Python 3.9+ License: MIT Downloads

Features

  • 30 cost checks across 5 categories (Compute, Storage, Networking, Database, General)
  • Severity classification — HIGH, MEDIUM, LOW with effort estimates
  • Beautiful terminal output — Rich tables, panels, color-coded findings
  • Export reports — JSON and CSV formats for stakeholder sharing
  • Demo mode — Try instantly without Azure credentials
  • Filtering — By severity level or resource category
  • Optimization grading — Letter grade (A-F) based on savings potential

Quick Start

Install

pip install azure-cost-optimizer

Or install from source:

git clone https://github.com/SanjaySundarMurthy/azure-cost-optimizer.git
cd azure-cost-optimizer
pip install azure-cost-optimizer

Run Demo

azure-cost scan --demo

See All Checks

azure-cost summary

Usage

Scan with Demo Data

# Full scan with demo data
azure-cost scan --demo

# Filter by severity
azure-cost scan --demo --severity HIGH

# Filter by category
azure-cost scan --demo --category COMPUTE

# Export JSON report
azure-cost scan --demo --export-json report.json

# Export CSV report
azure-cost scan --demo --export-csv findings.csv

# Combine filters and export
azure-cost scan --demo --severity HIGH --category DATABASE --export-json critical-db.json

Available Commands

Command Description
azure-cost scan --demo Run cost analysis with demo data
azure-cost summary Show all 30 checks the tool performs
azure-cost --version Show version

What It Checks

Compute (7 checks)

Check Severity Potential Savings
Stopped but allocated VMs HIGH ~85%
Idle VMs (< 5% CPU) HIGH ~95%
Underutilized VMs (< 20% CPU) MEDIUM ~40%
Dev/test VMs without auto-shutdown MEDIUM ~65%
Reserved Instance candidates LOW ~38%
Scale sets with fixed instance count MEDIUM ~30%
Overprovisioned App Services HIGH ~60%

Storage (5 checks)

Check Severity Potential Savings
Unattached managed disks HIGH 100%
Premium disks with low IOPS MEDIUM ~65%
Old snapshots (> 90 days) MEDIUM 100%
Aging snapshots (> 30 days) LOW ~80%
Hot storage with infrequent access MEDIUM ~45%

Networking (5 checks)

Check Severity Potential Savings
Orphaned public IP addresses HIGH 100%
Load balancers with no backends HIGH 100%
Load balancers with no rules MEDIUM ~50%
Unused NAT Gateways HIGH 100%
Oversized Application Gateways MEDIUM ~35%

Database (8 checks)

Check Severity Potential Savings
Oversized SQL Databases (low DTU) HIGH ~55%
SQL storage over-provisioned LOW ~10%
Dev/test DBs on production SKUs HIGH ~80%
Idle Cosmos DB accounts HIGH ~90%
Over-provisioned Cosmos DB RUs MEDIUM ~45%
Oversized Redis Cache MEDIUM ~50%
Idle Redis Cache HIGH ~95%
Underutilized MySQL servers MEDIUM ~45%

General (5 checks)

Check Severity Potential Savings
Empty resource groups LOW
High-cost untagged resources MEDIUM
Untagged resources LOW
Resources in expensive regions LOW ~20%
Long-running resources (> 1 year) LOW

Architecture

azure_cost_optimizer/
├── cli.py              # Click CLI entry point
├── scanner.py          # Orchestrator — runs all analyzers
├── models.py           # Data models (Severity, Category, CostFinding, etc.)
├── demo.py             # Demo mode with realistic mock data
├── analyzers/
│   ├── base.py         # Abstract base analyzer
│   ├── compute.py      # VM, scale set, app service checks
│   ├── storage.py      # Disk, snapshot, storage account checks
│   ├── networking.py   # Public IP, load balancer, NAT gateway checks
│   ├── database.py     # SQL, Cosmos DB, Redis, MySQL checks
│   └── misc.py         # Resource groups, tags, regions
└── output/
    ├── console.py      # Rich terminal rendering
    └── report.py       # JSON/CSV export

Development

# Install with dev dependencies
pip install azure-cost-optimizer

# Run tests
pytest -v

# Run linter
ruff check .

# Run with demo
azure-cost scan --demo

Tech Stack

  • Python 3.9+ — Core runtime
  • Click — CLI framework
  • Rich — Terminal formatting and tables
  • pytest — Testing framework
  • ruff — Linting

License

MIT License — see LICENSE for details.

Author

Sanjay S — Senior DevOps Engineer

🐳 Docker

Run without installing Python:

# Build the image
docker build -t azure-cost-optimizer .

# Run
docker run --rm azure-cost-optimizer --help

# Example with volume mount
docker run --rm -v ${PWD}:/workspace azure-cost-optimizer [command] /workspace

Or pull from the container registry:

docker pull ghcr.io/SanjaySundarMurthy/azure-cost-optimizer:latest
docker run --rm ghcr.io/SanjaySundarMurthy/azure-cost-optimizer:latest --help

🤝 Contributing

Contributions are welcome! Here's how:

  1. Fork the repository
  2. Create a feature branch: git checkout -b feature/amazing-feature
  3. Commit changes: git commit -m 'Add amazing feature'
  4. Push to branch: git push origin feature/amazing-feature
  5. Open a Pull Request

Please ensure tests pass before submitting:

pip install azure-cost-optimizer
pytest -v
ruff check .

🔗 Links

About

CLI tool to analyze Azure resources and identify cost optimization opportunities with actionable recommendations

Topics

Resources

Contributing

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages