What is this?

This knowledgebase contains questions and answers about PRTG Network Monitor and network monitoring in general.

Learn more

PRTG Network Monitor

Intuitive to Use. Easy to manage.
More than 500,000 users rely on Paessler PRTG every day. Find out how you can reduce cost, increase QoS and ease planning, as well.

Free Download

Top Tags


View all Tags

Custom GPU Sensor via NVSMI and bat script

Votes:

0

Hey I'm using nvsmi to get the gpu utilization on my clientmachine. I created a .bat script with following code and added it via Advanced EXE/XML Sensor

@echo off echo ^<?xml version="1.0" encoding="Windows-1252" ?^> echo ^<prtg^> echo ^<result^> echo ^<channel^>GPU0 Power Draw^</channel^> echo ^<float^>1^</float^> echo ^<value^> echo "C:\Program files\NVIDIA Corporation\NVSMI\nvidia-smi.exe" --query-gpu=utilization.gpu --format="csv,nounits,noheader" echo ^</value^> echo ^</result^> echo ^</prtg^>

The Command "C:\Program files\NVIDIA Corporation\NVSMI\nvidia-smi.exe" --query-gpu=power.draw --format="csv,nounits,noheader" returns a float value, like 86.3 if I paste it in cmd. But in PRTG in returns 0# as a value. It happens if I use --query-gpu=power.draw, or --query-gpu=temperature.gpu as a parameter for nvsmi too. so I guess there's a formatting error in my sensor code.

-bat custom-script-exe custom-sensor gpu nvidia nvsmi prtg script

Created on Sep 28, 2020 1:59:22 PM



7 Replies

Votes:

0

Hello,

please enable the "Result to disk" option in the sensor in order to check what the sensor reads from the console.

It could be that the executable does not run unless you change the security context in the sensor in order to run with user impersonation using the device object's Windows credentials.

It could also be that the output has to be changed, using comma instead of dot.

Created on Sep 29, 2020 2:25:34 PM by  Arne Seifert [Paessler Support]

Last change on Sep 29, 2020 2:26:48 PM by  Arne Seifert [Paessler Support]



Votes:

0

The results of this Sensor: <?xml version="1.0" encoding="Windows-1252" ?> <prtg> <result> <channel>GPU Utilization</channel> <float>1</float> <value> "C:\Program files\NVIDIA Corporation\NVSMI\nvidia-smi.exe" --query-gpu=utilization.gpu --format="csv,nounits,noheader" </value> </result> </prtg>

I guess the problem is that I can't connect to the target device. Maybe I need to integrate winrs in this script ?

Created on Oct 2, 2020 9:36:25 AM

Last change on Oct 2, 2020 1:23:54 PM by  Arne Seifert [Paessler Support]



Votes:

0

Hello,

it seems that the smi tool is not executed, because the command itself is written as output value. Please make sure that the command is executed and its output somewhere stored so that you can use it for the script.

Created on Oct 2, 2020 11:41:08 AM by  Arne Seifert [Paessler Support]



Votes:

0

Hello,

indeed, the script is run on the probe, not on the target device. This leaves you two options:

  • Use remote-powershell in the script. You can pass login credential from the PRTG device either with parameters, or with environment variables
  • Run the script via Windows Scheduler directly on the target, have it perform an HTTP POST to communicate with a HTTP Push Data Advanced sensor setup on a PRTG probe.

Created on Oct 2, 2020 1:26:25 PM by  Arne Seifert [Paessler Support]



Votes:

0

Im not that well with PS or HTTP Push Data Syntax, so I found another way by writing the value of nvsmi to a file and access via .bat script.

@echo off
FOR /F "tokens=* delims=" %%x in (\\pcname\logs\gpu_temp.csv) DO echo %%x

The script is working so far, but I need to create a script for each machine I want to monitor. Is there a way to import "%host" parameter in the batch file? Then I could replace "pcname" in the file path.

Created on Oct 2, 2020 1:44:21 PM



Votes:

0

Hello,

you can pass parameters to the script. Inside the script, parameters are normally processed as if the script was started via the command line.

Created on Oct 5, 2020 3:08:42 PM by  Arne Seifert [Paessler Support]



Votes:

0

Created on Jun 8, 2021 9:41:12 AM




Disclaimer: The information in the Paessler Knowledge Base comes without warranty of any kind. Use at your own risk. Before applying any instructions please exercise proper system administrator housekeeping. You must make sure that a proper backup of all your data is available.