Cost monitoring and analysis

Cost monitoring and analysis

If you are an Azure administrator, you are probably responsible for monitoring and managing the cost of all services hosted in the cloud. There are many factors related to this particular case—the types of used resources, the scale of your projects, or different discounts that you may apply, depending on the contract you have with Microsoft. Azure offers different options to make your life easier—starting from easy-to-read dashboards to cost alerts, which help you to monitor the current usage. In this section, you will learn how to use those tools and understand their outcome.

Before you really get started with hosted services, you can estimate the cost of the architecture using the following calculators:

  • Pricing calculator: An Azure cost calculator, which can be found at https://azure.microsoft.com/en-us/pricing/calculator/, it is a tool that you can use to estimate how much each Azure service will cost. Of course, these calculations are only estimates as it is really hard to plan everything upfront. Nonetheless, treat it as the first step in planning funds for your architecture.
  • Total Cost of Ownership (TCO) calculator: This is another Azure calculator, which is available at https://azure.microsoft.com/en-us/pricing/tco/calculator/. Using the cloud is not only about using cloud services, but also about changing the responsibilities and moving expenses from one place to another. This calculator helps you to understand the total cost of your architecture including managing server infrastructure, updates, licenses, and many more. 

The preceding tools are great to understand the expected cost of the whole cloud architecture that we are about to manage. However, they require that you know how each service is configured and what features will be enabled. Doing this upfront may be tricky, so they are not always an ideal solution for managing the cost. This is why we will have to take a look at the real usage and calculated cost to be able to control it.

To work with cost analysis, you will need a working Azure subscription. The important thing here is also correct permission assigned to your account—you have to be able to read subscription cost data (by being, for example, the owner of a subscription).

Cost management is enabled by default on all subscriptionsall you need here is to access the correct section in the Azure portal:

  1. To access the cost management option, search for it in the search field at the top of the portal:
Figure 1.31 – Searching for the Cost Management blade

From this point, you can access different blades such as Cost analysis, Budgets, and CloudynWhen you enter the subscription screen, you should be able to see a screen similar to mine:

Figure 1.32 – Current cost charts

Let’s focus quickly on the information displayed here. We have two categories, which inform us about the current cost of the subscription:

  • Cost by resource: This chart displays the total cost of the subscription divided by the resources. As you can see, in my case, almost 90% of the cost is generated by a resource named kamzcosmos (which is probably an Azure Cosmos DB instance).
  • Spending rate and forecast: This is an interesting chart that gives you an insight into the forecast of your spending. It also allows you to see how dynamically the cost changes.
The Spending rate and forecast chart may look a little bit different depending on the type of your subscription. In the preceding example, I presented a subscription that has a fixed limit of 130 EUR allowed for each month. When using, for example, a PAYG subscription, starting credit will not be displayed.

When you go to the Cost Management, you will see a new blade where multiple features are available:

Figure 1.33 – The Cost analysis blade

The available options will be briefly described in the following.

Cost analysis

To get a better overview of how much each resource costs (or a resource group or a location), you can use Cost analysis to get a personalized view of different spending categories. Besides the main chart representing the accumulated view, you will have access to three additional charts, which you can alter to get a different categorization of resources:

Figure 1.34 – Cost analysis per service name, location, and resource group name

There are many interesting categories that you can use to understand the cost—you can divide services using tags, their tiers, invoice number, or even their GUIDs. If you have many resources, this becomes especially helpful as it allows you to use advanced filtering and better distinction.

Budgets

Microsoft Azure allows you to create budgets, which you can use to control the cost of the cloud services. To use this feature, you have to go to the Budgets blade and click on the + Add button. Doing so will display a form that you can use to set a budget with an alert, which will trigger if the current cost of your subscription exceeds the threshold:

Figure 1.35 – Creating a budget

In the preceding example (Figure 1.35), I have created a budget of 90 USD with an alert that will trigger if I spent at least 90 USD.

Note that the Amount field of the budget relates to the currency set for the subscription.

There is an additional feature of budgets that, from your perspective, should be very interesting. As you have probably noticed, you can divide your budget into many categories, each triggering another kind of action group. Action groups can be managed by clicking on the Manage action groups button:

Figure 1.36 – Setting the alert of a budget

They allow you to enhance your budget with an additional level of automation using services such as Azure Functions, Azure Logic Apps, or Azure Automation to take a specific action in addition to sending an alert. Here, you can find an example with a runbook, which will stop all virtual machines in a resource group:

Figure 1.37 – Creating an action for a budget

Once a budget is created, you can see it in the main window of the feature:

Figure 1.38 – Budget status

Here, you can find an example mail triggered by defined alert rules. Note that it contains all of the necessary details you need to understand what is happening—when the budget started, what is its maximal value, and the current state:

Figure 1.39 – Budget alert email result

Such an email can be really valuable, especially when limiting expenses is crucial for a business to run smoothly. The important thing here is that you should not rely on a single channel of communication only—the email message could get lost or your mailbox might have gone down—if the budget alert is really important, always implement a backup plan for it.

Azure Advisor

In most cases, the Azure portal features should fit most of your needs. One more thing worth mentioning is Azure Advisor, which you can find in the Cost Management blade:

Figure 1.40 – Advisor recommendations blade

By clicking on it, you may find helpful tips related to the cost optimization for your subscription. If you have many different resources, it may be worth checking once in a while whether you have missed some occasions for saving extra money by tweaking provisioned resources.

When you set alerts via budgets in the cost management of your subscription, you will get an email each time you reach the threshold. As in most cases, you will not be the only administrator; a group of people will be notified to take a look and check which resources are utilizing the budget the most. You will find this feature really helpful, especially if you have a strict requirement when it comes to cloud cost. By adding action groups, you can plan automated saving based on the rules you define. We can think of an example here:

  • When you reach 75%, you send an email to all administrators.
  • When you reach 85%, you can run a script that will scale down Dev/Test environments.
  • When you reach 90%, you send an SMS to all administrators, send an email to all engineers, and shut down Dev/Test environments.

With such flexibility, you can think of several scenarios that will be appropriate to your current workloads and the characteristics of your systems.

You just learned about budgets and how to configure them to monitor your resources. Let’s now continue with other automation solutions that may help you to keep an eye on the Azure services and applications you manage.

Related Articles

How to add swap space on Ubuntu 21.04 Operating System

How to add swap space on Ubuntu 21.04 Operating System

The swap space is a unique space on the disk that is used by the system when Physical RAM is full. When a Linux machine runout the RAM it use swap space to move inactive pages from RAM. Swap space can be created into Linux system in two ways, one we can create a...

read more

Lorem ipsum dolor sit amet consectetur

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *

16 − four =