Shut Down idle VM's [Azure]

Idan Ohayon
Cloud Computing
June 11, 2020

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.

No alt text provided for this image
No alt text provided for this image



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.

No alt text provided for this image
No alt text provided for this image




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:

No alt text provided for this image


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.

No alt text provided for this image



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.


Idan Ohayon

Experienced System Engineer with a demonstrated history of working in the information technology and services industry. Skilled in Suite, Internet Protocol Suite (TCP/IP), SQL, Group Policy, and System Administration. Strong information technology professional with a MCITP Certified Support Technician /A+ focused in Computer/Information Technology Administration and Management from IITC.

Keep Reading

Newsletter EuropeClouds.com

Thank you! Your submission has been received!

Oops! Something went wrong while submitting the form