gabrielweyer / azure-vm-pricing

Mass-pricing of VMs on Azure based on CPU cores count and memory.
MIT License
26 stars 16 forks source link
azure lift-and-shift virtual-machine

Azure VM pricing

Mass-pricing of VMs on Azure based on CPU cores count and memory. This is useful when costing a lift-and-shift migration dealing with many thousands VMS of varied sizes.

:rotating_light: This tool will only provide you with an estimation. Depending on your Azure spend you might be able to get a better deal from Microsoft. You should use the output of this tool as a coarse-grain estimation. On top of the VM price you will also need to consider storage and egress costs.

This tool is composed of two components:

  1. A Parser retrieving the prices from Virtual Machines Pricing
  2. A Coster using the output from the Parser and a list of VM specifications to determine their price

This approach allows to decouple price acquisition from its usage and open the door to automation. The Parser can be scheduled to retrieve the prices at regular interval and the Coster can then use always up-to-date prices.

Build Status (tests documentation)

Build Status

Parser

Retrieve VMs hourly prices for a specific combination of culture, currency, operating system and region.

:rotating_light: the parser is not - yet - able to retrieve prices for the regions east-china2, north-china2, east-china and north-china as it is available on a different website.

:rotating_light: the parser is not able to retrieve prices for the regions us-dod-central and us-dod-east as no virtual machines are listed as publicly available.

Parser pre-requisites

> cd .\parser\
> yarn

Parser usage

> cd .\parser\
> yarn crawl --culture en-us --currency usd --operating-system linux --region us-west --output-path .\out\

You can also use short names:

> yarn crawl -l en-us -c usd -o linux -r us-west -p .\out\

Arguments:

Parser output

Writes 2 output files in the out\ directory, or the directory specified by the --output-path argument. One is a CSV, the other one is JSON. Both files contain the same data.

.\out\vm-pricing_<region>_<operating-system>.csv
.\out\vm-pricing_<region>_<operating-system>.json

Fields:

Docker

Build the Docker image

You can build a Docker image for the azure-vm-pricing:

# Parser Docker image
cd parser
# For Linux machines running on x86_64 or in Windows WSL
docker build -f ./Dockerfile --platform linux/amd64 --build-arg ARCH=amd64 -t azure-vm-pricing .
# For Linux machines running on arm64, for example Apple Macbooks with Apple Silicon
docker build -f ./Dockerfile --platform linux/arm64 --build-arg ARCH=arm64 -t azure-vm-pricing .

Run the Docker image

You can run the azure-vm-pricing image:

docker run --rm -it -v ./data:/data/ azure-vm-pricing:latest bash -c "yarn crawl --culture en-us --currency eur --operating-system linux --region europe-west -p /data/"

Coster

Price VMs using the JSON prices files generated by the Parser. The Coster will select the cheapest VM that has enough CPU cores and RAM.

Coster pre-requisites

Coster usage

You should paste the JSON prices files generated by the Parser in the coster\src\AzureVmCoster\Prices\ folder. Setting the culture is only relevant when dealing with prices and input files that were written using another culture with a different decimal point (e.g. comma vs period).

In Release mode:

> cd .\coster\src\AzureVmCoster
> dotnet run --configuration Release -- --input <input-path> --culture <culture>
> dotnet run --configuration Release -- --input <input-path> --configuration <configuration-path>
> dotnet run --configuration Release -- -i <input-path> -l <culture>
> dotnet run --configuration Release -- -i <input-path>

The culture is optional.

You can exclude VMs by providing a configuration file, see Coster configuration.

In Debug mode:

> cd .\coster\src\AzureVmCoster
> dotnet run --configuration Debug
Input file path: <input-path>
Configuration file path (leave blank if not used): 
Culture (leave blank for system default):

You'll need to provide the <input-path> when prompted, the configuration file path and culture are optional.

<input-path> should point to a CSV file with the following fields:

The columns can be in any order and the CSV file can contain extra-columns. The Region and Operating System fields must match existing regions and supported operating systems in the Virtual Machines Pricing website.

Coster output

The Coster will generate a CSV file in the Out\ directory with the following fields:

Supported cultures

Supported cultures (newer cultures might have been added after I last updated the README, they're likely to be supported):

Supported currencies

Supported currencies (newer currencies might have been added after I last updated the README, they're likely to be supported):

Supported OS/Software

Supported OS/Software (newer OS/Software might have been added after I last updated the README, they're likely to be supported):

Supported regions

Supported regions (newer regions might have been added after I last updated the README, they're likely to be supported):

Coster configuration

The only configuration available currently is excludedVms, it takes an array of instance names. These instances won't be considered when costing VMs.

For example, if you want to discard all burstable VMs, you can use the below configuration file:

{
  "excludedVms": [
    "B2ts v2",
    "B2ls v2",
    "B2s v2",
    "B4ls v2",
    "B4s v2",
    "B8ls v2",
    "B8s v2",
    "B16ls v2",
    "B16s v2",
    "B32ls v2",
    "B32s v2",
    "B2ats v2",
    "B2als v2",
    "B2as v2",
    "B4als v2",
    "B4as v2",
    "B8als v2",
    "B8as v2",
    "B16als v2",
    "B16as v2",
    "B32als v2",
    "B32as v2",
    "B1s",
    "B1ms",
    "B2s",
    "B2ms",
    "B4ms",
    "B8ms",
    "B12ms",
    "B16ms",
    "B20ms"
  ]
}