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.

See also  Checking Wi-Fi Signal Strength in Linux Using Terminal: A Comprehensive Guide

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

5/5 - (1 vote)

Mohamed SAKHRI

I am Mohamed SAKHRI, the creator and editor-in-chief of Tech To Geek, where I've demonstrated my passion for technology through extensive blogging. My expertise spans various operating systems, including Windows, Linux, macOS, and Android, with a focus on providing practical and valuable guides. Additionally, I delve into WordPress-related subjects. You can find more about me on my Linkedin!, Twitter!, Reddit

Leave a Comment