The cost analysis is one of the crucial activities while working on any Azure application. As Azure services involve some cost so an organization (small or big) should have an automatic mechanism to download reports on a schedule basis, review, and analyze it to understand the insights about expenses.
Cost Management has a Cost Analysis feature using that cost reports can be scheduled and generate. Cost Analysis provides four options to schedule an export report, and these are –
- Daily export of month-to-date costs
- Weekly export of last 7 days
- Monthly export of last month’s cost
- One-time export
Now, we will create four types of reports and generate the CSVs. Export only supports CSV format, but if needed to transform data into a different formats like JSON etc., then Azure Data Factory can be leverage.
Login to Azure Portal and create a general purpose V2 storage account to export the reports in CSV format.
Once the storage account is ready, then do a global search for Cost Management + Billing and select it, then from the left side pane select Cost Management.
Now, change the scope to Azure Subscription by clicking on the Scope. This step is needed because this will decide what would get extracted.
Once the scope has been added to calculate the cost analysis, then click on the download option from the main screen and click on View All Export. It will open the cost management export window.
Now, the next step is to create an export schedule, and to do that click on the “Add” option and perform the below steps
- Enter the report name DailyReport to create Daily export of Month-to-Date report.
- Select the Azure subscription and storage account <demosacostanalysis>.
- Give container name as reports and directory as daily. The container name and directory names could be of your choice.
- Click on the Create.
Similarly, create the other three types of reports based on the options available in Export type. Now, exports screen would have four types of scheduled exports.
Use weekly, monthly, and custom as directory name input respectively.
Now, scheduled exports have been created successfully, and we want to see the output. If you don’t want to wait for the execution, then select All reports and click on the Run now.
Once all the runs have been completed, then the storage account <demosacostanalysis> must have all reports in their respective directory inside the container reports.
Go inside “daily” folder and see the generated CSV file.
In the same way, go inside the other report folders and verify the output csv file.
This implementation has done at an Azure Subscription level, but cost analysis can also be done at a resource group level because every resource group has cost analysis option under cost management settings.
So, we have seen how cost analysis scheduled exports can be configured and generate the reports based on our requirements. 🙂