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

Disk Latency Sensor & Powershell Authentication Issues

Votes:

0

Overall objective is to create disk latency sensors to get sec/write and sec/write from Windows servers. Here's what I've tried so far, any guidance greatly appreciated.

  1. Inbuilt sensor - I couldn't find one, could you please add this to the feature request list.
  2. Custom WMI sensor - "SELECT AvgDisksecPerWrite FROM Win32_PerfFormattedData_PerfDisk_PhysicalDisk" rounds down the values to 0 so doesn't give anything useful.
  3. Custom Powershell (code below) - The script works from a powershell prompt on the probe device (logged on with my credentials) when run against any server. The script works in PRTG when the $hostname parameter passed is the probe device but for any other server the get-counter method errors (error.txt => Get-Counter : Unable to access the desired machine or service. Check the permissions and authentication ....). The sensor security context is "Use Windows credentials of parent device" and the parent device (ie server) settings are set to override defaults and use my credentials. Powershell is set to "unrestricted". I think this may be an issue with not being able to passthrough credentials multiple levels but, as get-counter doesn't support -cred parameter I can't workaround that. Does PRTG work with powershell scripts that query remote computers? All the demo scripts just reference 127.0.0.1.

Any ideas on how else to get these values would be greatly appreciated.

#(Powershell script for sec/write)
param($hostname, $disk)
# $hostname = "_servername_removed_"
# $disk = "_Total"
$countername = "\PhysicalDisk("+$disk+")\Avg. Disk sec/Write"
$counter = Get-Counter -ComputerName $hostname -Counter $countername
$error | Out-File c:\temp\error.txt
[float]$value = (($counter.Readings.Split("`n"))[1])
$value = $value * 1000
write-host $value,":OK"

custom-script-exe custom-sensor disk get-counter powershell prtg

Created on Oct 12, 2010 2:09:52 PM

Last change on Mar 20, 2015 1:20:53 PM by  Martina Wittmann [Paessler Support]



4 Replies

Votes:

0

Hello,

PRTG is able to execute or work with scripts that query remote computers with WMI.

As for testing, have you tried specifying the password & username directly in the script? Does it work then? Then as a next step you could check if it works using parameters to pass on username & password.

Best Regards.

Created on Oct 13, 2010 1:25:45 PM by  Torsten Lindner [Paessler Support]



Votes:

0

Torsten,

Thanks for the update.

Custom powershell scripts with WMI queries against remote computers are not currently working from within PRTG unless we specify the username and password in the script (Error = Get-WmiObject : Access is denied). This is with sensor security context set to "Use Windows credentials of parent device". Assuming you believe a Powershell WMI query should be able to be issued against a remote computer, can we please troubleshoot this?

If we can fix that then I think the get-counter command will probably start working.

I'm afraid a straight WMI call is not an option as stated above, due to the Formatted class values always being 0 (this is not PRTG specific). I can't work out how to cook the values from the Raw class (current code below) to get correct values so that is not an option.

It's not possible to pass a username and password with the original non-wmi powershell script as the get-counter method doesn't support it.

Remember that the overall goal is just to get disk latency stats from Windows Servers so if there's another way to do this please ignore the above and point me to that.

Thanks,

James

############
# WMI Script (inbuilt credentials) for attempted cooking of raw disk latency perf stats (doesn't return correct values - formula or execution must be incorrect).   Same script without credentials doesn't work when called against remote $hostnames.

param($hostname, $disk)

$username="xxxxx"
$password="yyyyyyyyy"	
$secureString=convertto-securestring $password -AsPlainText -Force
$cred = new-object -typename System.Management.Automation.PSCredential -argumentlist $username,$secureString      

#$hostname = "servername"
#$disk = "_Total"

#$c1 = Get-WmiObject -class "Win32_PerfRawData_PerfDisk_PhysicalDisk" -ComputerName $hostname | ft
	Get-WmiObject -credential $cred -ComputerName $hostname -query "select AvgDisksecPerWrite,AvgDisksecPerWrite_Base,Timestamp_Sys100NS,Frequency_PerfTime from Win32_PerfRawData_PerfDisk_PhysicalDisk where Name ='_Total' " | %{[Int64]$c1w = $_.AvgDisksecPerWrite; [Int64]$c1wb = $_.AvgDisksecPerWrite_Base; $c1t = $_.Timestamp_Sys100NS; $c1f = $_.Frequency_PerfTime}

	sleep 5

	Get-WmiObject -credential $cred -ComputerName $hostname -query "select AvgDisksecPerWrite,AvgDisksecPerWrite_Base,Timestamp_Sys100NS,Frequency_PerfTime from Win32_PerfRawData_PerfDisk_PhysicalDisk where Name ='_Total' " | %{[Int64]$c2w = $_.AvgDisksecPerWrite; [Int64]$c2wb = $_.AvgDisksecPerWrite_Base; $c2t = $_.Timestamp_Sys100NS; $c2f = $_.Frequency_PerfTime}
#"$c2w,$c1w,$c2wb,$c1wb"

$error | Out-File c:\temp\errorWMI.txt

$value = ((($c2w - $c1w)/$c1f)/($c2wb-$c1wb)) * 1000 
write-host $value,":OK"

Created on Oct 13, 2010 2:10:10 PM

Last change on Oct 13, 2010 2:58:20 PM by  Daniel Zobel [Product Manager]



Votes:

0

AvgDiskSecPerWrite is of Countertype 805438464 (PERF_AVERAGE_TIMER). It is calculated according to this formula:

(Nx - N0) / F) / (Dx - D0)

Further Information can be found here:

http://msdn.microsoft.com/en-us/library/ms804010.aspx

You need to take at least two successive measurements to get the right value.

We strongly consider implementing such a sensor, but have no schedule yet.

Created on Oct 14, 2010 1:28:19 PM by  Torsten Lindner [Paessler Support]

Last change on Oct 15, 2010 1:39:05 PM by  Daniel Zobel [Product Manager]





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.