maybe not a good idea

adventures in scripting.

Monitoring GPU Performance on Windows via PRTG and nvidia-smi

Last time we talked about Monitoring GPU Performance on Windows via PRTG and OpenHardwareMonitor. Today I would like to introduce the possibility to do this with NVIDIA’s smi.

The NIVIDIA System Management Interface is a small command line tool. You can find it here: C:\Program files\NVIDIA Corporation\NVSMI\nvidia-smi.exe. As PRTG needs a very specific output, smi needs to generate a very specific output. In fact: just the unit of the utilisation.
This can be done with these parameters:

1
C:\Program files\NVIDIA Corporation\NVSMI\nvidia-smi.exe' --query-gpu=utilization.gpu --format="csv,nounits,noheader" --id=$ID

So now smi ouputs the current gpu utilisazation of the GPU with the ID $ID. The rest is pretty simple: we provide our credentials to the script and execute the command remotely via Invoke-Command. In addition I built a loop for the command, because most of the render server provide more than one GPU. So with this loop we’ll get the correct amout and value of all provided GPUs. We’ll also provide the result in the specific scheme for a PRTG custom EXE/XML sensor. So we’re able to use only one sensor and every GPU gets its own sensor. Here we go:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
param(
[string]$cn, #computername
[string]$un, #username
[string]$pw, #password
[string]$dn) #domain
$Password = $pw | ConvertTo-SecureString -AsPlainText -Force
$Username = $dn+'\'+$un
$cred = New-Object System.Management.Automation.PSCredential($Username,$Password)
$number = Invoke-Command -ComputerName $cn -Credential $cred -ScriptBlock { & 'C:\Program files\NVIDIA Corporation\NVSMI\nvidia-smi.exe' -q }
$numberfilter = $number | find "Attached GPUs"
$amount = ($numberfilter) -replace '\D+(\d+)','$1'
"<prtg>"
For ($i = 0; $i -lt $amount; $i++) {
"<result>
<channel>"
"GPU $i"
"</channel>
<value>"
Invoke-Command -ComputerName $cn -Credential $cred -ArgumentList $i -ScriptBlock {param($i) & 'C:\Program files\NVIDIA Corporation\NVSMI\nvidia-smi.exe' --query-gpu=utilization.gpu --format="csv,nounits,noheader" --id=$i}
"</value>
</result>"}
"</prtg>"

The parameters for the custom sensor are the same than last time: '%host' '%windowsuser' '%windowspassword' '%windowsdomain'


© 2017 Martin Groiss