In our previous post you learned how to get started with using PowerCLI against vR Ops and how to use the cmdlets to work with alerts, in this post we take you a step further an learn how to take the work from the previous post and use it with Recommendations and Statistics from vR Ops.
As part of an alert which we discussed previously, vR Ops provides recommendations that guide you to possible solutions. These recommendations are available as well via the Get-OMRecommendation cmdlet. Continuing with the example, now that I have taken ownership of an alert I can easily grab the recommendation.
The recommendation is to consolidate snapshots, which I can also do via PowerCLI (actually, I will just delete the snapshot since I do not need it any longer). But to do this I need the VM object. Happily, the vR Ops resource object is provided as a property of the alert. I simply need to retrieve it and here we see it contains the MOID.
Even better, you can simply use the VI module cmdlet Get-VM with the vR Ops resource to retrieve the VM object. From here it is just a matter of getting the snapshot and deleting it.
To wrap up this introduction, I want to show how you can easily retrieve metric data (or stats) from vR Ops using PowerCLI. Many times customers will ask if they can export metric data from vR Ops for usage in other analytical tools or reports. While there are other methods, the PowerCLI module offers a really elegant way to extract that data.
The cmdlet Get-OMStat will provide the metric data output but it is useful to review the cmdlet Get-OMStatKey first. vR Ops stores hundreds of metrics for CPU, memory, disk, networking and other items. For example, if you browse the Troubleshooting > All Metrics tab for a VM you can see all the metric data available.
Each of these metrics is contained in a construct called statKeys in vR Ops. For example, as the screenshot above shows, Average Demand in KB for Memory is stored as memory|averagedemand(kb) within vR Ops. To retrieve these statKeys programmatically you need to use the Get-OMStatKey cmdlet as shown below where I list the statKeys for a virtual machine resource (the $vmresource vra7 used in the alert examples above).
A lot of metrics! And that is just for CPU related metrics. I will select a specific statKey based on the name.
Now I can get the stats for the resource and statKey. In the example below I am getting daily metric averages for the last 30 days.
By the way, the values for the –IntervalType parameter are:
- Seconds
- Minutes
- Hours
- Days
- Weeks
- Months
- Years
Also, the –IntervalCount parameter is a multiplier. If I specified a value of “7” instead of “1” I would have a weekly aggregation of the daily averages, as below.
There is a lot more capability than I have shown here, but hopefully this gives you a good start. For customers who have deep expertise in Powershell and PowerCLI the vR Ops integration can be a huge help.
In our next post we will talk more about how you can access 100% of the vR Ops public API and show a few examples of how to create functions that enable you to work with vR Ops to solve even more issues.
John Dias is a Staff Systems Engineer on VMware’s Solution Engineering and Technology team specializing in Cloud Management solutions.
John is a veteran IT professional with over 22 years of experience, most of that having been on the customer side running data center operations, data storage, virtual infrastructure and Unix environments for a major financial institution.
He normally blogs at storagegumbo.com and in his spare time he enjoys astronomy and astrophotography.