Last active
October 6, 2021 13:38
-
-
Save prombouts/ed0bd566792abc7d281908a58dbe70b3 to your computer and use it in GitHub Desktop.
Check usage limits in Azure
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
#!/bin/bash | |
echo "Starting..." | |
# Get all VM usage as json | |
vmjson=$(az vm list-usage --location westeurope -o json) | |
# Loop through all items and check whether limit has been reached | |
# If so, log to DevOps logger so pipeline will reflect warnings or errors | |
jq -c '.[]' <<< "$vmjson" | while read i; do | |
# Get values from JSON | |
currentValue=`jq -r .currentValue <<< $i` | |
limit=`jq -r .limit <<< $i` | |
localName=`jq -r .localName <<< $i` | |
perc=0 | |
if [ "$limit" -gt "0" ]; then | |
perc=`echo "scale=2; $currentValue / $limit * 100" | bc` | |
fi | |
percint=${perc%.*} | |
if [ "$percint" -ge "85" ]; then | |
echo "##vso[task.logissue type=warning;]Running low on free $localName resources. Usage $perc"; | |
fi | |
if [ "$percint" -ge "95" ]; then | |
echo "##vso[task.logissue type=error;]Running very low on free $localName resources. Usage $perc"; | |
fi | |
echo "Usage percentage $perc [$localName]" | |
done | |
echo "Finished!" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment