Capturing Citrix XenServer performance data with PowerShell

23 Aug 2017 by Ryan Ververs-Bijkerk

Category:

    Citrix

Capturing Citrix XenServer performance data with PowerShell

Table of Content

  • Requirments for SSH
  • Capturing the XenServer data
  • Downloading the data from XenServer
  • Conclusion

Capturing performance data is important to fully understand the impact of changes. With automation, you can guarantee a consistent data capture which is important to compare different scenarios. In this blog post, I’m going to share how to capture Citrix XenServer performance data with PowerShell.

Requirments for SSH

In order to fully automate the capturing, you need a way to connect to the XenServer host using SSH. This can be done with the PowerShell module Posh-SSH which is required for the examples below. You can install the module manually or use the following example to install the module automatically.

Please note: an internet connection is required.
if (!(Get-PackageProvider | Where-Object {$_.Name -eq "NuGet"})) {
    Write-Host "Default NuGet package provider not installed."
    Write-Host "Installing NuGet package provider."
    Install-PackageProvider -Name "NuGet" -Confirm:$false -Force
    Set-PSRepository -Name "PSGallery" -InstallationPolicy "Trusted" 
}

if (!((Get-Module -ListAvailable *) | Where-Object {$_.Name -eq "Posh-SSH"})) {
    Write-Host "SSH module not found, installing missing module."
    Install-Module -Name Posh-SSH -Confirm:$false -Force
}

Capturing the XenServer data

To capture the performance data a couple of variables needs to be assigned. First, it is important to specify the XenServer host, username and password. These will be used to connect to the XenServer host using SSH. The testname will be used as the primary name for the CSV file. Consistent data is important so you can compare multiple scenarios. The timeout and delay are used to define the total time to capture the data and the interval. In the example below data is captured for 10 minutes with a 30 seconds interval. I’m always using jobs to capture performance data because this allows me to do other tasks during the capture.

RRD2CSV is the primary tool for capturing the performance data. More information can be found here.

$HostName = "Xen01.local.lab"
$XenUserName = "root"
$XenPassword = "Password123!"

$TestName = "Logitblog-exmaple-" + (Get-Date -format 'MM.dd.yy_HH.mm').ToString()
$TimeOut = 600

$delay = 30
$path = "/root/$TestName.csv"

$command = "timeout $($TimeOut)s rrd2csv -s $delay > $path"

$password = ConvertTo-SecureString $XenPassword -AsPlainText -Force
$hostCredential = New-Object System.Management.Automation.PSCredential ($XenUserName, $password)

Start-Job -Scriptblock {
    Param(
        [PSCredential]$jobCred,
        [string]$jobHost,
        [string]$jobCommand
    )  

    $session = New-SSHSession -ComputerName $jobHost -Credential $jobCred -AcceptKey
    Invoke-SSHCommand -Index $session.SessionId -Command $jobCommand
    Get-SSHSession | Remove-SSHSession | Out-Null
} -ArgumentList @($hostCredential, $HostName, $command)

Downloading the data from XenServer

In order to analyze the results, you need to download the performance data from the XenServer host. This can also be done using the Posh-SSH module! Using the Get-SCPFile you are able to download the file to your local disk.

$localFile = "$env:Temp\" + $TestName + ".csv"
Get-SCPFile -HostName $HostName -RemoteFile $path -LocalFile $localFile  -Credential $hostCredential
A quick tip! With the PPD you can quickly create charts in Microsoft Excel out of the XenServer performance data! More info here.

Conclusion

With the examples above you are able to fully automate capturing and downloading performance data from XenServer. Thanks to the module Posh-SSH this can be done with PowerShell. Using this method is a consistent way to capture the data so you can compare different scenarios. I hope this blog post is useful and if you have any comments or questions please leave them below.

Photo by Chris Holgersson on Unsplash

Tags:
    automation
    citrix
    powershell
    ppd
    xenserver
Ryan Ververs-Bijkerk
Written by Ryan Ververs-Bijkerk

Ryan is a self-employed technologist at GO-INIT who specializes in the EUC and code area. He primarily focuses on the user experience in centralized desktop environments.

Search

    Follow me

    Community