LoginVSI PowerShell – Perfmon


A large number of LoginVSI tests I perform are single user tests.  I want to compare a single user’s bandwidth usage, RAM usage, CPU usage, etc. I know that LoginVSI incorporates monitoring, but these tests, I prefer perfmon data.

How do I get perfmon to start capturing metrics when a user logs in and stop when a user logs off?  How do I automate the filenames for the perfmon captures so I can easily identify different tests?

V4-VSI-Logon.cmd

LoginVSI already has a file that gets executed when a user logs on (\\domaincontroller\netlogon\V4-VSI-Logon.cmd). I will simply add a command to this file that launches a PowerShell script

CALL "\\vsi-mgmt\VSIShare\_VSI_Binaries\Target\Logon.cmd"
Powershell -NoProfile -ExecutionPolicy Bypass -Command "& '\\dc1\automation\Monitor\Perfmon.ps1'"

Perfmon.ps1

The second item is to create the Perfmon.ps1 file referenced in the V4-VSI-Logon.cmd. Capturing metrics is easy with the Get-Counter PowerShell command.

# Generate a perfmon csv file with a filename of MasterImage-VSIWorkload-Test#of#-Date-Time

# Variables used to identify the specific test
$MasterVM = "Win16-CTX1808"
$Testdesc = "WAN"
$Workload = "Video360p"
$cycle = 2
$TotalCycles = 2
$computername = hostname

$time = get-date -format yyyy-MM-dd----HH-mm-ss
$Path = "\\dc1\perfmondata\$MasterVM-$Workload-$testdesc-Test $cycle of $TotalCycles on VM $computername - $time.csv"

# Need to ID the session for the ICA metrics
$session = $env:sessionname
$session = $session -replace "#", " "

Get-Counter -counter "\Processor(_Total)\% Processor Time","\ICA Session($session ($env:username))\*","\Memory\% Committed Bytes in Use","\Memory\Available MBytes","\LogicalDisk(_Total)\Disk Reads/sec","\LogicalDisk(_Total)\Disk Writes/sec","\Network Interface(*)\Bytes Received/sec","\Network Interface(*)\Bytes Sent/sec","\Network Interface(*)\Bytes Total/sec" -SampleInterval 1 -Continuous | Export-Counter -path $Path -FileFormat CSV -Force

 

Set-Perfmon

The third item is to create a new function called Set-Perfmon that manipulates the Perfmon.ps1 script by updating the variables to align with the current test (used for the filename).

Function set-Perfmon {
    Param(
        [string] $workload,
        [string] $testdesc,
        [string] $MasterImage,
        [int] $i,
        [int] $cycles
    )

        #Update Perfmon Logon Script
    $argumentlist = '"{0}"' -f $workload
    $LogonScript=Get-Content "\\dc1\automation\Monitor\Perfmon.ps1"
    $LogonScript  | Foreach-Object {
            $_ -replace "Workload =.+", "Workload = $ArgumentList"
    } | Set-Content "\\dc1\automation\Monitor\Perfmon.ps1"
        
    $argumentlist = '"{0}"' -f $testdesc
    $LogonScript=Get-Content "\\dc1\automation\Monitor\Perfmon.ps1"
    $LogonScript  | Foreach-Object {
            $_ -replace "Testdesc =.+", "Testdesc = $ArgumentList"
    } | Set-Content "\\dc1\automation\Monitor\Perfmon.ps1"
        
    $argumentlist = '"{0}"' -f $MasterImage
    $LogonScript=Get-Content "\\dc1\automation\Monitor\Perfmon.ps1"
    $LogonScript  | Foreach-Object {
            $_ -replace "MasterVM =.+", "MasterVM = $ArgumentList"
    } | Set-Content "\\dc1\automation\Monitor\Perfmon.ps1"
        
    $LogonScript=Get-Content "\\dc1\automation\Monitor\Perfmon.ps1"
    $LogonScript  | Foreach-Object {
            $_ -replace "cycle =.+", "cycle = $i"
    } | Set-Content "\\dc1\automation\Monitor\Perfmon.ps1"
        
    $LogonScript=Get-Content "\\dc1\automation\Monitor\Perfmon.ps1"
    $LogonScript  | Foreach-Object {
            $_ -replace "TotalCycles =.+", "TotalCycles = $cycles"
    } | Set-Content "\\dc1\automation\Monitor\Perfmon.ps1"

}

New-CitrixVSITest

The Set-Perfmon function is called from within the New-CitrixVSITest function.

Quite handy!

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Blog at WordPress.com.

Up ↑

%d bloggers like this: