Difficulty: easy
Requirements:
Azure automation account with Runas account
So how are we going to do it?
We are about to create an alert that checks every 15 mins for low CPU usage VM's and triggers Azure automation runbook to shut down that specific VM and send us an email.
Note: it is possible to implement a similar solution to shut down VM's Regardless of specific resource group, it requires log analytics and PowerShell runbook (Maybe in the next guide 😊).
Step 1: create Alert
a. Navigate to alerts on the top search and click on new alert rule.
b. Click on Select resource, filter by Virtual machine, and choose the relevant resource group.
c. Click on Done.
Step 2: create condition
a. Click on Select condition.
b. Choose Percentage CPU.
c. Configure the following:
Operator: less than
Threshold value: 2 (or the CPU usage that indicates a lack of use for you)
Aggregation granularity (period) : 15 Mins
Frequency of evaluation: 15 Mins
d. Click Done.
Step 3: Select Action Group
a. Click on Create action group and fill the fields as you like and click OK.
b. Now we will create two actions
Action 1:
Action Name: Trigger-Runbook
Action type: Automation Rubook
In the new window choose Runbook type Stop VM
Choose the relevant subscription and automation account and click OK
Action 2:
Action Name: Notify-Email
Action type: Email / SMS
Check email and write the email you want to receive notifications for shut down.
Click OK and wait a few seconds till the action group creation complete.
Step 4: Complete Alert
a. Click on select action group and choose the action group we have created earlier.
b. Write name and description, choose resource group.
c. Click on Create Rule.
That is all folks
Feel free to IM me for any issue
You are welcome to contact my amazing company @neway if you need a project or consulting company to guide you on your journey to the cloud.