DEV Community

Bablu Lawrence
Bablu Lawrence

Posted on • Updated on

Stop(deallocate) inactive Azure Virtual Machines automatically

At present Azure gives you below approaches to reduce compute cost of Azure Virtual Machines with variable usage pattern - such as the ones used for development and testing.

These approaches require setup to be done for each individual VM separately. However, if you have lot of VMs spread across multiple resource groups in different subscriptions, setting up and managing these solutions takes lot of work. In other words, these solutions doesn't scale very well.

I wrote an app to solve some of these issues:

GitHub logo bablulawrence / vmautostop

Stop(deallocate) inactive Azure Virtual Machines automatically

VmAutoStop - stop(deallocate) inactive Azure Virtual Machines automatically

Intended for optimizing compute costs of dev/test virtual machines. Not recommended for VMs running production or critical workloads.

At present Azure gives you below approaches to reduce compute cost of Azure Virtual Machines with variable usage pattern - such as the ones used for development and testing.

These approaches require setup to be done for each individual VM separately. However, If you have lot of VMs spread across multiple resource groups in different subscriptions, setting up and managing these solutions takes lot of work. In other words, these solution doesn't scale very well.

This app is an attempt to solve some of these problems. Using this you will be able to select all VMs in resource group for auto stopping by adding a resource tag and setting…

Here is how it works :

An Azure Function app runs every minute and gets a list of VMs in the subscriptions that it has access to. It then reads VM metric values - Percentage CPU and Network Out and calculates their standard deviation. If the standard deviation is less than the predefined threshold, VM is deemed inactive and a warning email is sent. Subsequently VM is stopped if it continues to be inactive.

Assumption is that the variance/standard deviation of CPU utilization and Network traffic for an inactive VM is lower than an active one. This is certainly seems true for VMs which has users logged in using SSH(Linux) or Remote Desktop(Windows) to performing dev/test activities. However this assumption might not be applicable for VMs running workloads with uniform resource consumption patterns and therefore app might not be useful for such cases.

Top comments (0)