Tag Archives: vCHS

Retrieving VM Metrics from vCloud Air

Recently I was working with vCloud air and PowerCLI and was asked if there was a way to retrieve the statics of a VM and export these to get a better idea of the utilization of that VM.

Working with vCloud Air and the API through the PowerCLI cmdlets I was able to use the GetMetricsCurrent() and GetMetricsHistoric() to retrieve both the current VM Metrics and also the historic metrics of a VM.  The type of metrics and their values is described here.

VM Current Metrics

Current metrics are instantaneous values collected at the time the request is processed. The GetMetricsCurrent() method retrieves a list of current metric values, one for each category. I put this into a handy function which can be found at the end of this post, with this function we can pass vCloud AIR VMs into it and retrieve the current metrics.

image

VM Historic Metrics

Historic metrics are collected and stored for 14 days. A call to the GetMetricsCurrent() method retrieves the past 24 hours of metric history.  again I created a function that allows us to select a VM (or multiple) and get the historic data for this VM.

image

You will see that this time the method returns a collection of results in the Sample entry, we can then expand this to return the results for the metric over the last 24 hours.

image

Creating a VM Statistical report

Of course with this being PowerShell we can add value to these results, I mean who wants to look at a long list of numbers, wouldn’t you rather see a pretty graph?  We can easily use Luc’s great Export-XLSX function to export the results for each metric straight into Excel and even create us a nice graph for each statistic:

image

image

The Functions

Make sure you download Lucs Export-Xlsx function from here, and below are the functions I used to retrieve this information from vCloud Air.

Function Get-CIVMMetric {
	Param (
		[Parameter(Mandatory=$True,ValueFromPipeline=$True,ValueFromPipelinebyPropertyName=$True)]
		$CIVM
	)
	Process {
		foreach ($VM in $CIVM) {
			If ($VM.Status -ne "PoweredOn") {
				Write-Host "$VM must be Powered On to retrieve metrics"
				exit
			} Else {
				$Metrics = $CIVM.ExtensionData.GetMetricsCurrent()
				$metrics.Metric
			}
		}
	}
}

Function Get-CIVMHistoricalMetric {
	Param (
		[Parameter(Mandatory=$True,ValueFromPipeline=$True,ValueFromPipelinebyPropertyName=$True)]
		$CIVM
	)
	Process {
		foreach ($VM in $CIVM) {
			If ($VM.Status -ne "PoweredOn") {
				Write-Host "$VM must be Powered On to retrieve metrics"
				exit
			} Else {
				$Metrics = $CIVM.ExtensionData.GetMetricsHistoric()
				$metrics.MetricSeries
			}
		}
	}
}

# Get the Current Metrics for the VM
Get-CIVM sql-w-01a | Get-CIVMMetric

# List the Available Historical Metrics for the VM
Get-CIVM sql-w-01a | Get-CIVMHistoricalMetric

# Get the CPU Historical Metrics
Get-CIVM sql-w-01a | Get-CIVMHistoricalMetric | Where {$_.Name -eq "cpu.usage.average"} | Select -ExpandProperty Sample

$VMName = "sql-w-01a"
Foreach ($stat in (Get-CIVM $VMName | Get-CIVMHistoricalMetric)){
    Foreach ($Entry in $Stat) {
        $Data = $Entry.Sample | Select Timestamp, @{Name=($Entry.Name);Expression={$_.Value}}
        Export-Xlsx $Data C:\Temp\$VMName.xlsx -WorksheetName ($Entry.Name) -ChartType "xlXYScatterSmooth" -AppendWorksheet
    }
}

Installing the vCloud Hybrid Service Web Client Plugin

Recently Duncan Epping over at Yellow-Bricks wrote a great article showing how to get started with the vCHS Web Interface, building on top of his post, one of the things I like about the vCHS setup is the fact that you can view and manage your VMs in the same way you would manage your existing environment – through the web interface.  This post takes you through the install of the web interface and some initial looks at the web client once installed.

After initial install of your vSphere 5.5 environment and configuration of the vSphere Web Client you will find a plugin is available which will allow access to vCHS VMs from the Web Client, this is available for installation from the Web Client Home Page.

Requirements

To install the vCHS plugin you will need to access the vSphere Web-Client with a supported web browser, the latest version of Firefox or Chrome should work, at the time of writing this blog post the following versions were confirmed as working:

  • Chrome 35.0.1916.153 m
  • Firefox 30.0

Install Process

1. Log into the vSphere Web Client and click the Home button to arrive on the home page

1

2. Click the vCloud Hybrid Service Installer icon.

1

3. You will now arrive on the vCHS client plugin page.

2

4. Under the Basic Tasks section click Install the vCloud Hybrid Service plug-in

2

5. A dialog box will appear asking for your credentials to myvmware.com

Warning: You will need to ensure your MyVMware profile is complete by logging into the site and trying to download the plugin manually first, missing information in your profile can cause an issue with the download failing.

3

6. Once completed and installed you will be asked to logout and log back in for the plugin to be initialized.

4

7. Once you have logged out and back in you will now have access to the vCloud Hybrid Service plugin by clicking the below icon from the home page

5

vCHS Web Client plugin configuration

Once installed the following steps should be followed to configure the vCloud Hybrid Service plugin

1. Launch the vCloud Hybrid Service plugin from the home page in the vSphere web client

5

2. Select the Summary tab and then click Register vCloud Hybrid Service Account

6

3. Provide the URL for the vCHS Service and your credentials used to access your account and click the OK button

7

4. Once completed all registered vCloud Hybrid services will be displayed

8

5. You can now double click on a cloud instance to view the available resources

9

6. To manage Virtual machines select the Related Objects tab

10