Best practices for reducing Azure VM hours? - azure

I recently implemented SSRS on a Azure VM and was very surprised when I realized I would be billed for 100% of the hours in a month if my VM was running. This runs around $200 and is in no way economical for our small reporting service we use for about 5 days month. What are my options for reducing VM hours?
I have already established I can shutdown and deallocated the machine when we are not using it. Ideally though the service would go into some kind of sleep mode and reallocate when the service is pinged.

You pretty much figured it out: When a VM is running, you're billed for it. This is how it's always been in Azure: Whether utilizing 0% or 100% of the VM, you're billed for the running VM. Think of it as paying for reserved resources. Just like an apartment, where you pay for the rent even if you're using it 0% (e.g. not home).
You can choose to stop the VM at any time, and billing stops, until you start the VM again. This is easily done via PowerShell / CLI, so you can automate it with your own tooling.
Note that VM billing is actually per minute, so if you shut down a VM after 30 minutes, you're not billed for an entire hour.
Only you can decide the proper way to manage your VM's uptime, based on your app's usage. There's no single right answer to that. And there's no mechanism for the VM to sleep if it detects inactivity. That's going to be an application-dependent thing (deciding when to shut down).

You have a couple of options to correct address this:
You could use automation, where you run a Powershell script to turn you VM off during off-peak time. Check this out:http://azure.microsoft.com/blog/2014/08/20/azure-automation-capabilities-in-depth-the-azure-automation-powershell-cmdlets/
You can setup alerts now in your account portal (yeah, I just said that!) Check it out here: http://azure.microsoft.com/en-us/documentation/articles/azure-billing-set-up-alerts/
I would look at both. You can shut-down a VM from PowerShell (MS just demonstrated that to me in a workshop this week), so I would use this approach if you know that SSRS is only going to run for a specified window.

You can also check Azure automation option if you have a definite schedule for the VM to be up and down. Azure automation gives you a way to create a runbook to manage the up time of the VM and also options to do the scheduling. Check this blog for more information https://blogs.endjin.com/2015/01/using-azure-automation-to-run-vms-during-office-hours-only/

Related

How can I automatically scale up a VM, run a console app and scale down the VM Daily on Azure

I have this app that I need to execute on a specific Azure VM (GPU heavy) daily. I don't want to pay for the machine running 24/7 and I am looking for a way to automate this. What would be the best approach for this?
I am reading up on Azure Runbooks but I'm not 100% sure if this can be achieved. I was also thinking if scheduling an Azure Devops Pipeline to run and scale up the machine and execute the console app and then automatic scaling down of a machine if the CPU load is low.
This seems like a typical and basic scenario to which I cannot find an easy solution.
You can start/stop VMs on a schedule in Azure. You could also modify your app to shutdown the server as soon as it exits so the VM is running for least possible time (instead of waiting for the scheduled shutdown).

Why the remaining credit amount is reducing although I'm not using the VMs?

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.

What events does an Azure Windows VM receive during a planned maintenance shutdown?

When Azure shuts down a VM for planned maintenance, what messages do running services see, if any?
For example, do they get a ServiceBase.OnShutdown() message and, if so, how long does the service / server get to complete shutdown processing?
Does MS give any extra leeway to its own apps? E.g. if a VM is running SQL Server, will Azure wait for SQL Server to stop cleanly before shutting down the VM?
[I can't find this in the documentation and, unfortunately, I don't have the access or the programming skills to try it out for myself.]
what messages do running services see, if any?
Based on my knowledge, for now, Azure does not support this. Please refer to this feedback.
Typically maintenance is performed at weekends for VMs not in an availability set to minimize impact on services. Normally notification is given 7 days in advance with the minimum being 3 business days. A start time for the maintenance is given with the expected duration. More information please refer to this link.
According to your description, I suggest you could provision another IaaS VM with your SQL server and put in the same Availability set. By doing this, Azure will ensure that both your VMs do not go down simultaneously.

Maximum cloud computing utilization - pay for computing, not idle time

I have one big task to do every day, with no need to scale, that takes about 30 minutes and is DB, processor and memory intensive.
This means actual 16h/month of computation time.
WebJobs require constantly running WebSite 744h/month
WebRole is also constantly running 744h/month
Azure Batch - suited for scaled storage input - storage output
processing (or that is how I understand it)
Stopped cloud service still cost you. Setting instance count to 0 is not available. And paying for 728h/month unused computation time looks like madness. Only thing I can imagine is automatic deployment of cloud service every day and automatic deletion of deployment once task is finished, but this also looks like madness.
Are there any options for this scenario in Azure?
Cloud service will be charged continuously until the deployment is deleted. Yes you can delete it every day and redeploy...
Azure VMs in Stopped (Deallocated) status, does not incur any charge. You can shut them down in portal or by script when you don't need them.
I think there is a large difference in billing if you only use it 62h/month. Would you consider switch this deployment to VM? WorkerRole and VMs can be placed on the same subnet, they can still connect to each other.

Cloud Services vs VM deployment Cost

We are working on architecture of new web application to be hosted on Azure. This application would run only in day time (Say 9AM to 5PM). What I read so far about Azure is we would continue be billed even when we stop the deployment.
However in case of Azure VM (IAAS) billing stops when we stop the VM.
Client is keenly interested in running the IT cost to the minimum. We are planning to use WASABi/Auto-scaling block to auto shutdown & auto-start the app to run only during (9AM-5PM)
Deploying application every morning & deleting every evening even programmatically doesn't sound like a good architecture.
Should we target the app for VM rather than Azure web role?
While hourly billing cost is definitely a consideration and it is true that if you stop a VM in IaaS, billing stops, there are other considerations as well. Some of them are:
With Cloud Services, you have to architect the application in a certain way to take advantage of statelessness there. So there may be a bit of a learning curve there. With Virtual Machines, in theory you can build an application the way you are used to and deploy that in the cloud.
With Cloud Services, the major advantage is that you don't have to maintain the VM. This is something Microsoft does that for you. So there's little or no IT-admin overhead. With VMs, maintaining the VM is your responsibility so that's an additional cost which is recurring as well (assuming you (or your client) have an IT Admin kind of guy on the payroll).
Generally speaking, if the application is a stand-alone application with quite simple deployment topology and is brand new application it is recommended that you write them as Cloud Service but do take the costs (development / IT admin) into consideration as well.
When you stop the virtual machine through a standard shutdown (through the machine itself for example), it does continue to incur charges. The portal will eventually show it as shutdown, but the VM still has resources allocated.
However, if you stop the machine through the portal, API, or PowerShell, it will stop and DEALLOCATE the machine. This means the VM will use storage space, but will not incur compute charges.
Simply schedule the deallocation of the machines during off-hours, and you will only page for the usage during the day.

Resources