- Visit: https://azure.microsoft.com/en-us/pricing/spot-advisor/#pricing
- Open the console via F12
- Paste the script
- Move between the different regions in the dropdown menu (click the dropdown and use the arrow keys to move between the regions quickly).
- Run getPlans(), or getPlansFromCheapestToMostExpensive(), or getRegionsFromCheapestToMostExpensive(), or getPlansFilteredByPlanTypeFromCheapestToMostExpensive(), or getRegionsFilteredByPlanTypeFromCheapestToMostExpensive().
- There is a better way to do that, I'm sure and ashamed of myself.
Last active
January 1, 2023 11:00
-
-
Save lukacat10/cc357e08ea19d779bceaab4f42534c13 to your computer and use it in GitHub Desktop.
Group azure spot instances by region
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let tableBody = document.querySelector(".data-table__table.data-table__table--pricing tbody"); | |
let regionSelector = document.querySelector("#pricing > div > div.row.row-size3 > div:nth-child(2) > div > select"); | |
function extractJsonFromTable() { | |
let currentRow = { | |
instance: "", | |
vcpu: "", | |
ram: "", | |
tempStorage: "", | |
payAsYouGo: "", | |
spot: "", | |
region: "" | |
} | |
let collectedRows = []; | |
for(let row of tableBody.children) { | |
currentRow = {}; | |
let columns = row.children; | |
currentRow.instance = columns[0].innerText; | |
currentRow.vcpu = columns[1].innerText; | |
currentRow.ram = columns[2].innerText; | |
currentRow.tempStorage = columns[3].innerText; | |
currentRow.payAsYouGo = parseFloat(columns[4].innerText.split("/month")[0].substr(1).replace(",","")); | |
currentRow.spot = parseFloat(columns[5].innerText.split("/month")[0].substr(1).replace(",",""));; | |
currentRow.region = regionSelector.value; | |
collectedRows.push(currentRow); | |
} | |
return collectedRows; | |
} | |
let allRows = []; | |
setInterval(() => { | |
if(allRows.find((row) => row.region === regionSelector.value) === undefined){ | |
allRows = allRows.concat(extractJsonFromTable()); | |
console.log("appended"); | |
} | |
}, 200) | |
function getPlans() { | |
return allRows; | |
} | |
function getPlansFromCheapestToMostExpensive() { | |
return getPlans().sort((row1, row2) => row1.spot > row2.spot ? 1 : -1); | |
} | |
function getRegionsFromCheapestToMostExpensive() { | |
return getPlansFromCheapestToMostExpensive().map((row) => row.region); | |
} | |
function getPlansFilteredByPlanTypeFromCheapestToMostExpensive() { | |
return getPlans().filter((row) => row.instance === "D4s v4").sort((row1, row2) => row1.spot > row2.spot ? 1 : -1); | |
} | |
function getRegionsFilteredByPlanTypeFromCheapestToMostExpensive() { | |
return getPlansFilteredByPlanTypeFromCheapestToMostExpensive().map((row) => row.region); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment