We have an Azure subscription and 100 VMs to serve as workstations, and due to cost reduction, I would like to set up an Azure VM automation to accomplish the following:
Check all 100 VMs for idle and no users connected state.
Automatically power off 50% of the idle VMs with no users connected on it and send email to admin
If the total used capacity/number of VM reach 90%, power on a certain number of VMs
Btw, all VMs are not in VMSS. Thanks.
We have an Azure subscription and 100 VMs to serve as workstations,
and due to cost reduction, I would like to set up an Azure VM
automation to accomplish the following:
Check all 100 VMs for idle and no users connected state.
Automatically power off 50% of the idle VMs with no users connected on it and send email to admin
If the total used capacity/number of VM reach 90%, power on a certain number of VMs
There are 2 ways you can accomplish this.
To check the CPU utilization percentage and send an alert with an email and shut down the VM’s via an action group. Create another alert to check VM’s CPU capacity reaching 90% and Power ON other Vm’s.
Refer -https://blog.e-zest.com/auto-stop-your-vm-based-on-cpu-utilization
To enable Log analytics workspace and get your VM’s syslog to check the uptime of the processes and events of the VM and then create an alert rule to send an email based on those logs and run an automation runbook or an action group to turn on/off the VM’s.
Refer -https://energizedanalytics.com/how-to-save-money-by-automatically-stopping-idle-virtual-machines-in-azure-2/
Approach 1)
I enabled Azure Monitoring for all the VM’s in my subscription like below which will log all Vm’s metrics, syslogs, events etc. :-
I created an alert with a scope selected to all the VM’s in my Subscription.
Created an alert to check the VM’s CPU utilization below 5 % to know it is idle and send an email notification like below :-
Create Azure Automation account to run the PowerShell script to Stop or Power off the VM when idle or CPU utilization is below 5%.
Click Next and Create.
Alert will be triggered like below and VM will be stopped.
Create a new alert to get Vm’s CPU utilization above 90% and run the automation to start the VM’s.
Approach 2)
Enable Log analytics for specific VM’s to get the Vm’s performance counters on Vm’s uptime.
Go to your Log Analytics Workspace > Agents Management > Data Collection Rule > Custom > Select Vm’s Uptime and create a rule to get all the Vm’s uptime like below :-
The logs will populate in the selected log analytics workspace> Create an Alert rule with Action group to stop the VM’s and start VM’s as above.
Create or select an existing Action Group and Create an Alert to start or stop the VM’s according to the CPU percentage.
Related
I have been following the learning path for Microsoft Azure AI 900. In the second module, I have deployed my model as an endpoint. It says Container instances for compute type. How much will this cost me. Azure doesn't seem to show any pricing for this. Is this endpoint always active? If yes how much does it cost?
The price depends on the number of vCPU and GBs of memory requested for the container group. You are charged based on the vCPU request for your container group rounded up to the nearest whole number for the duration (measured in seconds) your instance is running. You are also charged for the GB request for your container group rounded up to the nearest tenths place for the duration (measured in seconds) your container group is running. There is an additional charge of $0.000012 per vCPU second for Windows software duration on Windows container groups. Check here Pricing - Container Instances | Microsoft Azure for details
After Deployed the Azure Machine Learning managed online endpoint (preview).
Have at least Billing Reader access on the subscription where the endpoint is deployed
To know the costs estimation
In the Azure portal, Go to your subscription
Select Cost Analysis for your subscription.
Create a filter to scope data to your Azure Machine learning workspace resource:
At the top navigation bar, select Add filter.
In the first filter dropdown, select Resource for the filter type.
In the second filter dropdown, select your Azure Machine Learning workspace.
Create a tag filter to show your managed online endpoint and/or managed online deployment:
Select Add filter > Tag > azuremlendpoint: "< your endpoint name>"
Select Add filter > Tag > azuremldeployment: "< your deployment name>".
Refer here for more detailed steps
The scenario is as follows:
In company premise, there is a network that consists few machines.
The company has an Azure subscription.
Requirement:
To monitor the company's Network/Machines via Azure
If the company resource goes beyond a threshold limit then trigger alerts. Example, network bandwidth consumption, machine CPU/Memory usage, etc.
When such alerts occur then spin up new virtual machines or VM scale sets in Azure to handle the load.
The purpose is if the machines in on-prem goes above threshold limit then automatically provision VMs in Azure, as there are only few on-prem machines.
Please guide how to implement these use cases?
your question is a little confusing. You mention machines on premises and using Azure to monitor them. You can monitor on premises VMs using Azure but then you mention provisioning new Azure VMs via Scale Sets.
I'm not 100% where your workload is but assuming it is in Azure then if you are using VM Scale Sets it's very easy to scale in and out based on resource utilisation.
This can be configured as described here: https://learn.microsoft.com/en-us/azure/virtual-machine-scale-sets/virtual-machine-scale-sets-autoscale-portal
How do I set up an alert for underutilized Virtual Machine / Disks on a daily basis?
I have a few virtual machines that are not used and I want azure to send me an alert about the stats etc.
You can use Azure Advisor for this specific task:
https://learn.microsoft.com/en-us/azure/advisor/advisor-cost-recommendations#optimize-virtual-machine-spend-by-resizing-or-shutting-down-underutilized-instances
Advisor helps you optimize and reduce your overall Azure spend by identifying idle and underutilized resources. You can get cost recommendations from the Cost tab on the Advisor dashboard.
Now you can also set alerts on the same:
Azure Advisor alerts are now in preview.
https://azure.microsoft.com/en-in/updates/azure-advisor-alerts-are-now-in-preview/
I've "Visual Studio Enterprise" azure subscription. I initially got few credits. I think it was $200 for free. Earlier it used to show static remaining credit i.e. if I built two VMs and it cost $50 it would show $150. But since few days may be just past day remaining credit is continuously reducing.
The activities I have done so far. Earlier I was unable to connect to VM as outgoing connection was not allowed from my organisation. Since I have got permission I'm able to connect. After that I installed Active Directory Services on one of the VM.
I don't think till this step my credit amount got reduced except for the VMs I built.
I was trying to start and stop the VM using powershell but I wasn't able to do so. So I installed powershell azure modules. using Connect-AzAccount to connect and then used Start-AzVM and Stop-AzVm to start and stop the VMs. Just to clarify I keep the VMs in shut down mode so I don't keep getting billed.
Still the amount is being deducted. I ran Disconnect-AzAccount on suspicion that it might be causing the issue but still it hasn't fixed the issue.
Can any one help here?
There are mainly two ways to stop VM:
Stop the Azure VM locally: When you connect to the Azure VM with remote desktop, go to the Power options within Windows and select Shutdown, this will essentially “turn off” the VM and stop it from running. However, even though the VM won’t be running you WILL still be paying for the Virtual machine hardware allocation. Doing this will cause the Azure Portal to report the status of the VM to be “Stopped”.
Another way is to click Stop in the virtual machine page on the portal(or use Azure PowerShell or Azure CLI). Instead of just shutting down the Operating System, Azure will also deallocate the hardware (CPU and Memory) allocation. Doing this will cause the Azure Portal to report the status of the VM to be “Stopped (Deallocated)”.
Overall, both methods will reduce cost but not none of cost. You do still pay for the Azure Storage account usage, which is used for storig the VM’s .vhd disk image file. As a result, you will still incur some cost for the storage, but at least you will save on the VM resources.
Ref: Properly Shutdown Azure VM to Save Money
You need to identify what resource are been billed when VM is stopped or Stopped De-allocated.
Check the Cost analysis under Cost Management to identify the resource. Note that when VM is stopped you still pay for storage and other resources depending in your setup.
How to monitor Azure IaaS VM availability. how to get alerted in case if the VM goes down or gets restarted.
Existing Azure monitoring / Alert and diagnostics providing alerts on perf counters like CPU, memory and networking. Is there any KPI that we can consider as for to alert in case VM goes down.
We don't want to invest on SCOM and find an alternative for this.
You can use Azure Monitoring for that and also create alerts and use them based on performance counters (CPU / memory, etc)
Azure Monitoring
https://azure.microsoft.com/en-us/documentation/articles/monitoring-overview/
Receive alert notifications
https://azure.microsoft.com/en-us/documentation/articles/insights-receive-alert-notifications/
You can use it directly through the Azure Portal, or connect using c# for example. All the information you need is on the link above.
I had good results with the "Network In" metric.
Set an alert for "Network In" with these settings: number "Less than", time aggregation "Total", threshold "15000 bytes" (see what number works best for you) for a period of "Over the last 1 minute" with a frequency of "Every 1 minute".
How many VMs do you have running in your subscription? If you're running websites or web services then you could setup a site-to-site VPN tunnel and utilize PowerShell scripts to test availability. We use Task scheduler to call PowerShell scripts that perform HTTP GET against websites on specific machines to ensure that the machine is up.
You could also use Get-AzureVM to test for status of the VM.