How can I monitor the time difference between a Windows system and a ntp-server? I would like to do something like: get the time of the target Windows system (maybe by snmp?), then get the time of a specific ntp-server, then calculate the difference in seconds. After that I would like to deploy this sensor for every windows system monitored in prtg.


Article Comments

This is exactly what the SNTP Sensor does :) But it's only available for Probe systems (i.e. either the PRTG server itself or systems that have a remote probe installed).

The following script will actually query the target host and output the timediff to PRTG:

param( 
    $ntp = "",
    $target = "",  
    $windowsUserName = "", 
    $windowsPassword = ''
)

#region configuration section
# parameter im PRTG: -windowsUserName '%windowsuser' -windowsPassword '%windowspassword' -ntp <ntp server> -target <target server>
# create credential object
$secpasswd = ConvertTo-SecureString $windowsPassword -AsPlainText -Force
$credentials = New-Object System.Management.Automation.PSCredential ($windowsUserName, $secpasswd)

#endregion 

$time_ntp  = (Invoke-Command -ComputerName $ntp -Credential $credentials -ScriptBlock { return (Get-Date) } )
$time_target = (Invoke-Command -ComputerName $target -Credential $credentials -ScriptBlock { return (Get-Date) } )

$diff = New-TimeSpan -Start ($time_dc) -End ($time_opc)

Write-Host ([string]::Format("{0}:Offset between {1} and {2} is at {0} Seconds",($diff.TotalSeconds -replace ",","."),$ntp, $target))

Note that the script requires WMI Permissions as well as a correctly configured PowerShell environment.


Kind regards,
Stephan Linke, Tech Support Team


Jul, 2018 - Permalink

Thank you, but our ntp-servers don't run on Windows and therefore can't be queried by powershell in the described way. I'm aware of an Windows executable called w32tm which does just that, but I would like to avoid using powershell-remote-calls at all. Our Environment contains roughly 500 monitored Windows systems. It would probably cause a lot of load on the probes when running the sensor this way, won't it? Isn't there another way?

The only two ways I can think of are: - calling w32tm by invoke-command - creating a push-sensor on every Windows system and running a scheduled job on the target systems reguraly providing the time-difference data by using w32tm

I'm just worried about the load on the probes.


Jul, 2018 - Permalink

Executing one small script on a host periodically would not increase the load on these. If you're referring to the load caused by the sensors - the HTTP Push Data sensors are really easy on the system. They basically do nothing else than wait for results :) We've recently installed a system with thousands of them with no issues so far.


Kind regards,
Stephan Linke, Tech Support Team


Aug, 2018 - Permalink