Azure Cost CLI – To track costs related to Microsoft Azure

Today, folks, I’d like to introduce you to a command-line tool that can be incredibly helpful if you’re in the Microsoft Azure ecosystem.

Depending on your activities with Azure instances and services, the costs can vary, and tracking them solely through the website can be impractical. Fortunately, with the Azure Cost CLI tool, you can monitor the expenses related to your resource usage directly from your device.

This software utilizes the Azure Cost Management API to retrieve costs and presents the results either directly in the console or in JSON format. The JSON output can then be leveraged in your tools or scripts.

Aside from viewing cumulative costs, as shown above, it can also display daily costs, extract resources by costs, and list budgets. Additionally, it can detect possible anomalies and trends in costs, further automating the generated reports.

To install it, it’s simple; open a terminal and use the following command (you’ll need dotnet):

dotnet tool install --global azure-cost-cli 

Then, you can start viewing the cumulative costs associated with a specific Azure subscription by passing your ID to it:

azure-cost accumulatedCost -s 12345678-1234-1234-1234-123456789012

To generate a CSV report of costs per resource, nothing could be simpler:

azure-cost costByResource -s 12345678-1234-1234-1234-123456789012 -o csv

Now, let’s say you want to view the daily costs for the month of January 2023, grouped by service name:

azure-cost dailyCosts --dimension ServiceName --from 2023-01-01 --to 2023-01-31

Convenient, isn’t it? And if you want to perform anomaly detection at the level of the costs generated during a certain period:

azure-cost detectAnomalies -g myResourceGroup --timeframe Custom --from 2023-01-01 --to 2023-01-31

I also discovered that this tool could be used in a GitHub Workflow to get the cost of our subscription and store the results in markdown. It’s really great to get a quick overview of the fees related to our subscription.

So, if you’re interested in tracking your costs on Azure, the Azure Cost CLI project is available here on GitHub.

Mohamed SAKHRI
Mohamed SAKHRI

I'm the creator and editor-in-chief of Tech To Geek. Through this little blog, I share with you my passion for technology. I specialize in various operating systems such as Windows, Linux, macOS, and Android, focusing on providing practical and valuable guides.

Articles: 1751

Newsletter Updates

Enter your email address below and subscribe to our newsletter

Leave a Reply

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