There are a few ways to pull performance counters off of Azure VMs and send them to a PI System:


1. Using the Azure REST API. These are the performance counters logged to the Azure VMs host hypervisor and what you see on the dashboard in the Azure management portal. As of now, there are 5 performance counters available, CPU Percentage, Disk Read Bytes/Sec, Disk Write Byes/Sec, Network In, and Network out:



2. The Azure WADPerformanceCountersTable. Performance counters can be written to Azure storage (in NoSQL format). This requires enabling Azure diagnostics on your VMs via PowerShell or the Azure portal. Any performance counter is available to be written; custom counters are supported as well.


3.  At the VM level using the PI Perfmon interface. This requires either a data center extended into Azure, a PI Data Archive at the local subscription level, or a VPN or IPSec tunnel back to a separate PI Data Archive.


For the purposes of this blog post, let’s focus on the first method since as long as you have a VM running in Azure, the counters are already there and we can pull them into a PI Data archive without additional configuration. While not every counter is available (just the 5 counters viewable on the dashboard in the portal), we are be able to backfill more information than is available in the portal and can create historical trends at high fidelity. If you’re interested in more finely tuned VM monitoring, or service monitoring I’d suggest the WADPerformanceCoutntersTable (this could also be the topic of a future blog post).


So what we’re going to do is develop two functions in PowerShell, one to get the Azure REST API metrics and one to write them to a PI Data Archive via the AFSDK. In the end, we’ll have 5 PI tags per VM holding the same 5 counters we see in the Azure portal dashboard. There are, however, four things to make sure you have in place in your running environment before getting into the PowerShell script:


1. Versions of the PowerShell Tools(4.0+) and Azure PowerShell tools(0.9.1+). The Azure Powershell cmdlets are currently in flux so certain cmdlet properties may be different between versions.

2. Appropriate certificate(s) stored to access your Azure subscription on the back end. The easiest way to get these is to do a onetime import of your .publishsettings file downloaded from your subscription.


A good getting started guide for numbers 1 and 2 can be found here: How to install and configure Azure PowerShell


3. Access to a PI Data Archive from the location you are running the script with appropriate permissions to create PI Points.

4. The AFSDK installed at the location you are running the script.


The script consists of two cmdlets, a Get-AzureRestAPIVMMetrics which does an Invoke-WebRequest to request data from Azure via the REST API and a Set-AzureRestAPIVMMetrics which writes the contents via the AFSDK to a PI data Archive.  You'll find the script in the below. The only line you'll have to edit is toward the end:


$subscriptionName = 'XXXXXXX' #Enter the name of your Subscription


Note that in the script it also possible to add a few lines here and build your own AF structure as you loop through these queries, rewrite this in C# and compile it, etc.


Looking forward to any feedback or questions you might have!





Edit: Make sure you're on the *permalink* in order to see the attachment:

Monitoring your Microsoft Azure VMs with the PI System and the Azure REST API