Hello! This is a quick blog post to demonstrate how to plot your Azure Metrics of any Resource in your PowerShell Console using the “Graphical Module” I’ve written sometimes back.

Let’s take a Virtual Machine as an example and navigate to the Metric section

Here we can choose a Metric Namespace and a Metric Name to see that metric plotted onto a chart as demonstrated in the following image.

Now, Let’s plot these metric datapoints into your PowerShell Console, but before that make sure you are logged into Azure and you have ‘Graphical’ Module installed on your machine. If not you can install it from PowerShell Gallery in case you are using PowerShell v5 and above. Post-installation make sure to import the module as well in the current PowerShell session.

Install-Module Graphical

Once that is done, use the below code and provide input values like Resource Name, Metric Name, Time Grain, Start and End time which is required to get metrics from Azure.

Now, use the Get-AZMetric cmdlet from the ‘Az’ module to download the metric data ( Percentage CPU - Average ) in your PowerShell Session and convert them into [int] values so that it can be plotted on an ASCII graph.

Now, we have the datapoint and it can be simply plotted in the console using the Show-Graph cmdlet from ‘Graphical’ Module using the following code snippet:

Plotting Azure metrics directly into PowerShell consoles is helpful in monitoring applications all from the comfort of shell 🙂

FULL CODE



~ Author of “PowerShell Guide to Python“, and currently writing a Book on “Windows Subsystem for Linux (WSL)“

All my books are available as a discounted bundle:

PowerShell Guide to Python : This PowerShell Scripting guide to Python is designed to make readers familiar with syntax, semantics and core concepts of Python language, in an approach that readers can totally relate with the concepts of PowerShell already in their arsenal, to learn Python fast and effectively, such that it sticks with readers for longer time. Windows Subsystem for Linux (WSL) : Keywords, definitions, and problems WSL solve and how it works under the hoods. From download to setup to interoperability this book even covers details like the architecture of Windows subsystem for Linux and new features in WSL 2 with some wonderful use cases.