Tooling to analyze Azure Virtual Machines for possible savings using Spot Instances
- This tool is made by Cloud Solution Architects from Microsoft OCP LATAM Team to assess partner environments, this is not a Microsoft Official Tool.
- All the prices presented here, are the ones provided by Azure APIs. For the final price, please contact your Cloud Provider.
- Before using Azure Spot Instances, please be sure you understand how it works, and what means to get a machine evicted. Azure Spot Instances Docs
You need to create the credentials so the project can list your virtual machines in Azure.
-
Create the Azure Service Principal and save the credentials to a json file.
az ad sp create-for-rbac --name "analyze-spot-vm" --sdk-auth true > my_credentials.json
-
Give the Service Principal the Reader role in your subscription.
az role assignment create --role Reader --assignee <<SP_CLIENT_ID>> --scope /subscriptions/<<SUBSCRIPTION_ID>>
To run the project you need the following data:
- SubscriptionId
- TenantId
- Client Id (from the service principal)
- Client Secret (from the service principal)
- Subscription Offer Id (you can find it in your subscription overview. Ex: MS-AZR-0015P)
- Your subscription Region (Ex: US)
- Clone this repository in your machine
- Enter the src folder.
cd src
- Run npm install to install the project dependencies.
npm install
To run the project in your terminal run the command
node index.js analyze \
--tenantId <<TENANT_ID>> \
--subscription <<SUBSCRIPTION_ID>> \
--client_id <<CLIENT_ID> \
--client_secret <<CLIENT_SECRET> \
--offerId <<OFFER_ID>> \
--location <<SUBSCRIPTION_REGION> \
--runningOnly <<true if you only want the running VMs>>
With docker installed and running in your machine, check the DockerHub repository for the latest tag of this project:
You can run the docker container with the following command
docker run latamocptechteam/azure-spot-vm-analysis:v0.1.1 --tenantId <<TENANT_ID>> \
--subscription <<SUBSCRIPTION_ID>> \
--client_id <<CLIENT_ID> \
--client_secret <<CLIENT_SECRET> \
--offerId <<OFFER_ID>> \
--location <<SUBSCRIPTION_REGION> \
--runningOnly <<true if you only want the running VMs>>
After running the script you will get the following results per VM and also consolidated.
- Estimated Cost for 730 Hours: The current cost you're paying having this VM online for a full month.
- Estimated Cost for 180 Hours: The estimated costs if you get this machine running only in work-time hours (9 hours a day)
- Spot Estimated Cost for 730 Hours: The estimated costs if you use Spot Instances for a full month.
- Spot Estimated Cost for 180 Hours: The estimated costs if you use Spot Instances and get this machine running only in work-time hours (9 hours a day)
- The first time you run can take some minutes, as the Retail Rates API returns a big json with all the price meters from Azure. Those information are than cached in a local json file, so the following executions will take significatly less time.