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

Monitoring Hyper-V Replication

Votes:

0

Is there already a way or plan to monitor VM replication in Hyper-V 3.0 (2012) in PRTG?

Regards, PeterFrentin

hyper-v prtg replication

Created on Apr 6, 2013 11:45:59 AM



Best Answer

Accepted Answer

Votes:

0

I know this is an old thread, but complementing the solution provided here and for those looking for a different approach, this is another way of doing it (the PRTG server itself will fetch the replications status, with no PSsessions). You need to enable the Hyper-V Powershell module/provider on your PRTG server/probe. Also, the Windows credential used for this sensor should be a member of the local group "Hyper-V Administrators" on the target servers (either this or a local Administrator), but I believe this is a requirement in any case (I use a GPO to define the prtg user as member of said group). Some PRTG tutorials suggest using a Domain Admin account for everything (which makes it easy), but I obviously don't consider this a good practice.

Read the script description for more details.

<#
.DESCRIPTION
This script is intended to be used with PRTG Network Monitor (as a custom "EXE/Script Advanced" sensor).
It will return the difference in minutes between the current date and the last time each VM replicated from
Primary to the Replica server.

Please make sure that the windows credential (domain user) used in PRTG (on this sensor) is a member
of the local group "Hyper-V Administrators" on the target Hyper-V servers. This is the only way, unfortunately.
Due to Hyper-V limitations, it is not possible do delegate "only read access" or something like this.

Some values are hard-coded: the script will consider 20 minutes as a limit for a "Normal" replication state and it
will trigger a "warning" alert (yellow) if any VM returns a value above said limit. The max value considered is 59 minutes,
over which the sensor will trigger an "error" alert (red). The script will not return values above 60 minutes. After that,
you can refer to the "Downtime" informed by PRTG (Down since X days, Y hours, etc).
#>

# Please provide the Hyper-V servers on the following line (replace by actual values):

$HVhost = "SERVER01", "SERVER02", "SERVER03"

# -----------------------

$CurrentDate = (Get-Date)

$Results = Get-VMReplication -Computer $HVhost | Select VMName, VMId, ReplicationMode, ReplicationHealth, ComputerName,`
                                             PrimaryServer, ReplicaServer, LastReplicationTime, ReplicationState `
                                             | Where-Object ReplicationMode -eq "Primary"

$xmlstring = "<?xml version=`"1.0`"?>`n    <prtg>`n"

ForEach ($eachresult IN $Results) {

$TotalMinutes = (New-Timespan –Start $eachresult.LastReplicationTime –End $CurrentDate).TotalMinutes

$xmlstring += "    <result>`n"
$xmlstring += "        <channel>$($eachresult.VMname)</channel>`n"
$xmlstring += "        <unit>Custom</unit>`n"
$xmlstring += "        <CustomUnit>min</CustomUnit>`n"
$xmlstring += "        <mode>Absolute</mode>`n"
$xmlstring += "        <showChart>1</showChart>`n"
$xmlstring += "        <showTable>1</showTable>`n"
$xmlstring += "        <float>0</float>`n"
$xmlstring += "        <value>$(IF ($TotalMinutes -lt 1) {"0"} ELSE {IF ($TotalMinutes -le 60) {$TotalMinutes.ToString("#")} ELSE {"60"}})</value>`n"
$xmlstring += "        <LimitMaxError>59</LimitMaxError>`n"
$xmlstring += "        <LimitMaxWarning>20</LimitMaxWarning>`n"
$xmlstring += "        <LimitWarningMsg>Hyper-V Replication for this VM is in Warning state</LimitWarningMsg>`n"
$xmlstring += "        <LimitErrorMsg>Hyper-V Replication failed for this VM and is in Critical state</LimitErrorMsg>`n"
$xmlstring += "        <LimitMode>1</LimitMode>`n"
$xmlstring += "    </result>`n"

 }

$xmlstring += "    </prtg>"

Write-Host $xmlstring

Save this as a .ps1 file in your \PRTG Network Monitor\Custom Sensors\EXEXML folder and create an Custom EXE/Script Advanced sensor in PRTG (you guys know the drill). It will actually monitor the delay between Primary VM and Replica VM. I use it in a map with the "Data Tables > Channels of a Sensor" map object.

Tested on a Windows Server 2012 and Windows Server 2012 R2 server (on these versions of Hyper-V as well). The PRTG server/probe needs to have execution policy enabled, as usual (RemoteSigned, for example).

I hope this helps.

Created on May 9, 2017 3:01:23 PM

Last change on May 10, 2017 6:27:35 AM by  Stephan Linke [Paessler Support]



22 Replies

Votes:

0

Hello,

thank you very much for this feature request! We appreciate it! I'm very much afraid currently there are no plans to support Hyper-V-Replication, but we have put it on the wishlist. If you'd like, please have a look at the following blog post by our CEO, explaining "How We Rate Your Feature Requests".

It may also be possible for you to create your own custom powershell sensor with powershell scripts similar to the one here Hyper-V Monitoring but you would have to develop this yourself. Custom Scripts

best regards.

Created on Apr 8, 2013 12:19:37 PM by  Torsten Lindner [Paessler Support]

Last change on Apr 8, 2013 12:36:57 PM by  Greg Campion [Paessler Support]



Votes:

3

Hi

Sorry, resurrecting an old entry. We are currently using the following to monitor our Hyper-v Replica's. It takes the hyper-v host the replica's are "stored" on as a variable. We currently run this from the probe device. You will need to probably set both the x32 and x64 powershell to at least a remotesigned execution policy for the local machine.

I am not a programmer so this is rough and use at your own risk

param(
[string]$Hypervserver
)

$Session = New-PSSession -computername $Hypervserver 

Import-PSSession $Session -Module Hyper-V

$VMReplication = Get-VMReplication | select name,health,state

Write-Host 	"<prtg>"

foreach ($Name in $VMReplication) {
if ($Name.Health -like "Normal" -and $Name.State -like "Replicating") {
$state = 0
}
else {
$state = 1
}
$VM = $Name.Name

Write-Host 	"<result>" 
		"<channel>$VM</channel>" 
		"<value>$state</value>"
		"<LimitMaxError>0.99</LimitMaxError>"
		"<LimitMode>1</LimitMode>"
		"</result>"
}

Write-Host 	"</prtg>"

#Added by mod
Remove-PSSession -ID $Session.ID
#Added by mod

Exit 0

Hope this helps some one

Edit: Included Remove-PSSession -ID $Session.ID to get rid of the temporary files/sessions, as pointed out by polskifacet here.

Created on Oct 6, 2014 8:47:24 PM

Last change on Jul 19, 2017 10:55:11 AM by  Luciano Lingnau [Paessler]



Votes:

0

Hey Rhyse,

We are dying to get a good replica monitoring. We daily check hundreds of replica statusses....if only prtg had a default sensor for this.... It seems quite simple if you are a programmer, but unfortunatley not for me. there are 3 results with hyper-v replica: normal/warning/critical. Seems like a perfect status for green/orange/red....

I tried your ps1 script, but cannot get it working. error: Response not wellformed: "(New-PSSession : Cannot validate argument on parameter 'ComputerName'. The argum ent is null or empty. Supply an argument that is not null or empty and then try the command again.

Can someone help?

Created on Dec 2, 2014 1:42:25 PM



Votes:

0

Which parameters did you fill in the parameter field of the sensor? Enter the host name of the sensor in quotes and see if you receive a valid result.

"hostname"

Created on Dec 3, 2014 1:42:44 PM by  Felix Saure [Paessler Support]



Votes:

0

Ok, that helped (I think)

after that filled in, I get a green response with the message 'UnauthorizedAccess' After setting x86 and x64 exectutionpolicy on probe, I get the same red response:

Response not wellformed: "(New-PSSession : [xxxxx.xxx.xxx] Connecting to remote server xxxx.xxx.xxx failed with the following error message : Access is denied. For more information, see the about_Remote_Troubleshooting Help topic

setting executionpolicy to unrestricted on hyper-v server does not solve this problem.

Created on Dec 9, 2014 8:11:14 AM

Last change on Jul 19, 2017 10:50:30 AM by  Luciano Lingnau [Paessler]



Votes:

0

Seems to be a problem with the remote permissions. Have a look at the following pages:

Entry at Technet for PSRemoting
http://technet.microsoft.com/en-us/library/hh849694.aspx

Enabling non-administrators http://blogs.msdn.com/b/powershell/archive/2009/11/23/you-don-t-have-to-be-an-administrator-to-run-remote-powershell-commands.aspx

Created on Dec 10, 2014 9:54:33 AM by  Stephan Linke [Paessler Support]



Votes:

0

I set up the script and get back even values, but with the error message "Answer not well-formed". Why is that?

Created on Jan 8, 2015 2:20:30 PM



Votes:

0

# param([string]$Hypervserver)
$Hypervserver = "servernameofthehypervbox"
# $Session = New-PSSession -computername $Hypervserver 

$VMReplication = Get-VMReplication | select name,health,state

$ErrMessage = " "
$Errors = 0
$Warning = 0
$Critical = 0
foreach ($Name in $VMReplication) {
    if ($Name.Health -like "Normal" -and $Name.State -like "Replicating") {
    $state = 0
    }
    elseif ($Name.Health -like "Warning") {
    $state = 1
    $Warning = $Warning + 1
    }
    elseif ($Name.Health -like "Critical") {
    $state = 1
    $Critical = $Critical + 1
    }


$VM = $Name.Name
$Health = $NAme.Health
$Status = $Name.State
$ErrMessage = $ErrMessage, $VM, " " , $Health , " ", $Status, "`t"
 $Errors = $Errors + 1
}

If ($Errors = 0 ){
Write-Host 0 , ":OK", "Replicating is working fine"
}
elseif ($Critical = 1) {
Write-Host 10 , ":", $ErrMessage 
}
elseif ($Warning = 1) {
Write-Host 5 , ":", $ErrMessage 
}
else {
Write-Host 2 , ":", $ErrMessage
}

#Added by mod
Remove-PSSession -ID $Session.ID
#Added by mod

Exit 0

change servernameofthehypervbox to your servername

With this you can set also Warning an Error limits (4 and 9)

Edit: Included Remove-PSSession -ID $Session.ID to get rid of the temporary files/sessions, as pointed out by polskifacet here.

Created on Jun 5, 2015 12:09:20 PM

Last change on Jul 19, 2017 10:54:40 AM by  Luciano Lingnau [Paessler]



Votes:

0

we also would like to get a more "integrated" solution for this issue

Created on Jan 27, 2016 10:49:41 AM



Votes:

0

Cleaned up the above scripts a bit (original left connections open). Also I have to run the below in CMD to get Windows 8 to work with the script. I also had to change the user that runs the PRTG service to a domain account.

%SystemRoot%\SysWOW64\WindowsPowerShell\v1.0\powershell.exe "Set-ExecutionPolicy RemoteSigned"
param([string]$Hypervserver)
$Session = New-PSSession -computername $Hypervserver 

Import-PSSession $Session -Module Hyper-V
 
$VMReplication = Get-VMReplication | select Name,Health,State

$ErrMessage = " "
$Errors = 0
$Warning = 0
$Critical = 0
foreach ($Name in $VMReplication) {
    if ($Name.Health -Contains "Normal" -and $Name.State -Contains "Replicating") {
    $stat = 0
    }
    elseif ($Name.Health = "Warning") {
    $stat = 1
    $Warning = $Warning + 1
    }
    elseif ($Name.Health = "Critical") {
    $stat = 1
    $Critical = $Critical + 1
    }

$VM = $Name.Name
$Health = $Name.Health
$Status = $Name.State
$ErrMessage = $ErrMessage, $VM, " " , $Health , " ", $Status, " "
	if ($stat -gt 0) {
	$Errors = $Errors + 1
	}
}

If ($Errors -eq 0 ){
Write-Host 0 , ":OK", "Replicating is working fine"
}
elseif ($Critical -gt 0) {
Write-Host 10 , ":", $ErrMessage 
}
elseif ($Warning -gt 0) {
Write-Host 5 , ":", $ErrMessage 
}
else {
Write-Host 2 , ":", $ErrMessage
}
Remove-PSSession -ID $Session.ID


Exit 0

Created on Feb 5, 2016 4:44:43 PM

Last change on Feb 10, 2016 12:38:54 PM by  Torsten Lindner [Paessler Support]



Votes:

0

Many thanks. Once I'd put the server name parameter within inverted single commas this works well. It would be nice if there was a supported integrated sensor for this.

Created on Jul 8, 2016 4:10:23 PM



Accepted Answer

Votes:

0

I know this is an old thread, but complementing the solution provided here and for those looking for a different approach, this is another way of doing it (the PRTG server itself will fetch the replications status, with no PSsessions). You need to enable the Hyper-V Powershell module/provider on your PRTG server/probe. Also, the Windows credential used for this sensor should be a member of the local group "Hyper-V Administrators" on the target servers (either this or a local Administrator), but I believe this is a requirement in any case (I use a GPO to define the prtg user as member of said group). Some PRTG tutorials suggest using a Domain Admin account for everything (which makes it easy), but I obviously don't consider this a good practice.

Read the script description for more details.

<#
.DESCRIPTION
This script is intended to be used with PRTG Network Monitor (as a custom "EXE/Script Advanced" sensor).
It will return the difference in minutes between the current date and the last time each VM replicated from
Primary to the Replica server.

Please make sure that the windows credential (domain user) used in PRTG (on this sensor) is a member
of the local group "Hyper-V Administrators" on the target Hyper-V servers. This is the only way, unfortunately.
Due to Hyper-V limitations, it is not possible do delegate "only read access" or something like this.

Some values are hard-coded: the script will consider 20 minutes as a limit for a "Normal" replication state and it
will trigger a "warning" alert (yellow) if any VM returns a value above said limit. The max value considered is 59 minutes,
over which the sensor will trigger an "error" alert (red). The script will not return values above 60 minutes. After that,
you can refer to the "Downtime" informed by PRTG (Down since X days, Y hours, etc).
#>

# Please provide the Hyper-V servers on the following line (replace by actual values):

$HVhost = "SERVER01", "SERVER02", "SERVER03"

# -----------------------

$CurrentDate = (Get-Date)

$Results = Get-VMReplication -Computer $HVhost | Select VMName, VMId, ReplicationMode, ReplicationHealth, ComputerName,`
                                             PrimaryServer, ReplicaServer, LastReplicationTime, ReplicationState `
                                             | Where-Object ReplicationMode -eq "Primary"

$xmlstring = "<?xml version=`"1.0`"?>`n    <prtg>`n"

ForEach ($eachresult IN $Results) {

$TotalMinutes = (New-Timespan –Start $eachresult.LastReplicationTime –End $CurrentDate).TotalMinutes

$xmlstring += "    <result>`n"
$xmlstring += "        <channel>$($eachresult.VMname)</channel>`n"
$xmlstring += "        <unit>Custom</unit>`n"
$xmlstring += "        <CustomUnit>min</CustomUnit>`n"
$xmlstring += "        <mode>Absolute</mode>`n"
$xmlstring += "        <showChart>1</showChart>`n"
$xmlstring += "        <showTable>1</showTable>`n"
$xmlstring += "        <float>0</float>`n"
$xmlstring += "        <value>$(IF ($TotalMinutes -lt 1) {"0"} ELSE {IF ($TotalMinutes -le 60) {$TotalMinutes.ToString("#")} ELSE {"60"}})</value>`n"
$xmlstring += "        <LimitMaxError>59</LimitMaxError>`n"
$xmlstring += "        <LimitMaxWarning>20</LimitMaxWarning>`n"
$xmlstring += "        <LimitWarningMsg>Hyper-V Replication for this VM is in Warning state</LimitWarningMsg>`n"
$xmlstring += "        <LimitErrorMsg>Hyper-V Replication failed for this VM and is in Critical state</LimitErrorMsg>`n"
$xmlstring += "        <LimitMode>1</LimitMode>`n"
$xmlstring += "    </result>`n"

 }

$xmlstring += "    </prtg>"

Write-Host $xmlstring

Save this as a .ps1 file in your \PRTG Network Monitor\Custom Sensors\EXEXML folder and create an Custom EXE/Script Advanced sensor in PRTG (you guys know the drill). It will actually monitor the delay between Primary VM and Replica VM. I use it in a map with the "Data Tables > Channels of a Sensor" map object.

Tested on a Windows Server 2012 and Windows Server 2012 R2 server (on these versions of Hyper-V as well). The PRTG server/probe needs to have execution policy enabled, as usual (RemoteSigned, for example).

I hope this helps.

Created on May 9, 2017 3:01:23 PM

Last change on May 10, 2017 6:27:35 AM by  Stephan Linke [Paessler Support]



Votes:

0

@victorclopes
Awesome, thanks for sharing that! :) I'll put it in our script world later today so more peole can find it.

edit Done, users can now find it via https://www.paessler.com/script-world :)

Created on May 10, 2017 6:41:50 AM by  Stephan Linke [Paessler Support]

Last change on May 10, 2017 7:48:18 AM by  Stephan Linke [Paessler Support]



Votes:

0

Hi, this script looks great but I need help getting it to work. A twist which I suspect is unique to my scenario compared to the ones above is that my Hyper-V server is NOT in the same domain as my Probe device. Unfortunately this is by design.

The full error I am receiving (looks best in a fixed-width block font):

Get-VMReplication : You do not have permission to perform the operation. 
Contact your administrator if you believe you should have permission to 
perform this operation.
At C:\Program Files (x86)\PRTG Network Monitor\custom 
sensors\EXEXML\ReplHealth.ps1:53 char:12
+ $Results = Get-VMReplication -Computer $HVhost | Select VMName, VMId, 
Replicatio ...
+            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : PermissionDenied: (:) [Get-VMReplication], Virtu 
   alizationOperationFailedException
    + FullyQualifiedErrorId : AccessDenied,Microsoft.HyperV.PowerShell.Command 
   s.GetVMReplicationCommand
 
<?xml version="1.0"?>
    <prtg>
    </prtg>

I followed all instructions I could find, including:

  1. Set the Powershell 32-bit execution policy on the Hyper-V server to RemoteSigned (I also tried Unrestricted): %SystemRoot%\syswow64\WindowsPowerShell\v1.0\powershell.exe Set-ExecutionPolicy Unrestricted
  2. Ensure the credentials used by the probe to access my Hyper-V server are included in the Hyper-V Administrators group. I even temporarily included "Everyone" in this group, but it didn't solve the problem.
  3. I prepended the following two lines on the script to confirm which account it's actually running under on the Hyper-V server, and they return NT AUTHORITY\SYSTEM (i.e. the Powershell script is being launched under the SYSTEM account): whoami [System.Security.Principal.WindowsIdentity]::GetCurrent().Name

I believe the Powershell portion of this (i.e. remote execution) is working fine, but something to do with security around the Hyper-V cmdlets is preventing it from working. The code runs fine until it hits the "Get-VMReplication" cmdlet.

Grateful for any help getting this to work!

Created on Sep 15, 2017 12:26:57 AM

Last change on Sep 15, 2017 6:11:27 AM by  Stephan Linke [Paessler Support]



Votes:

0

You probably need to install a remote probe on that HyperV host, since PowerShell authentication relies on kerberos, which only works within a domain and not from domain to workgroup :/


Kind regards,
Stephan Linke, Tech Support Team

Created on Sep 15, 2017 7:49:04 AM by  Stephan Linke [Paessler Support]



Votes:

0

Thanks Stephan; I was worried about that. Do you think it might be possible to craft a workaround given this lead: https://blogs.msdn.microsoft.com/taylorb/2012/03/23/hyper-v-remote-management-with-powershell/

Created on Sep 15, 2017 11:06:54 AM



Votes:

0

Maybe by replacing

$Session = New-PSSession -computername $Hypervserver 
Import-PSSession $Session -Module Hyper-V

with the following:

$remotingCreds = (Get-Credential) 
$Session = New-PSSession -Authentication Credssp -Credential $remotingCreds  -ComputerName $Hypervserver 
Import-PSSession $Session -Module Hyper-V

...or something like that, not sure :/ Credentials have to be created at runtime from username and password.


Kind regards,
Stephan Linke, Tech Support Team

Created on Sep 15, 2017 11:21:20 AM by  Stephan Linke [Paessler Support]



Votes:

0

I followed others and victorlclopes comments (unrestricted policy, proper user account access) . However, I am still unable to get this to work. When I run the script manually, it stops pretty quickly and throws this error -

Get-VMReplication : The destination host is not available. Specify another host and try the operation again.
At C:\Program Files (x86)\PRTG Network Monitor\Custom Sensors\EXEXML\MonitorReplication.ps1:25 char:12
+ $Results = Get-VMReplication -Computer $HVhost | Select VMName, VMId, Replicatio ...
+            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Get-VMReplication], VirtualizationOperationFailedException
    + FullyQualifiedErrorId : Microsoft.HyperV.PowerShell.Commands.GetVMReplicationCommand

PRTG shows "No result or error in XML response"

I can ping the host from the PRTG server. Why might it be showing as the destination host not available?

Created on Apr 12, 2019 3:53:19 PM

Last change on Apr 12, 2019 6:56:55 PM by  Stephan Linke [Paessler Support]



Votes:

0

Are you using the FQDN of your Hyper-V server? Is the FQDN properly resolved on the host? This is likely to be the issue here.


PRTGapi | Feature Requests | WMI Issues | SNMP Issues

Kind regards,
Stephan Linke, Tech Support Team

Created on Apr 15, 2019 6:29:09 AM by  Stephan Linke [Paessler Support]

Last change on Apr 15, 2019 6:29:31 AM by  Stephan Linke [Paessler Support]



Votes:

0

Great script and it works if I manually run it on the server that has the probe.

However I created the sensor in PRTG and all I get is:

No 'Result' or 'Error' in XML response

Any ideas?

Created on Sep 12, 2019 8:31:15 AM



Votes:

0

Hyper-V Replication might be monitored by "Folder" sensor. If HV Replica is working well, then the vhd- and vm-files at the HV Replication's destination folder are updated each time the replication is done, as their "creation time" does. If it isn't working - nothing is changed. Then set up a limit for "oldest file" according to your replication time.

Works perfectly.

Created on Dec 27, 2019 7:43:30 PM

Last change on Dec 27, 2019 7:43:30 PM



Votes:

0

Appreciate this is quite an old thread now but I'm hoping someone will see this post and be able to help me out!

I have a few hosts in my environment which are all standalone, local storage, no SANs, so a pretty basic setup which works beautifully for what I need. I have my hosts configured in pairs, for example HOST01 and HOST02 are a pair, I replicate my VMs from HOST01 to HOST02 and vise-versa. When VM01 is replicated, the replica is renamed to REPLICA_VM01, I want to exclude REPLICA_VM01 from showing up on my PRTG dashboard, is it possible to exclude VMs from monitoring within this script?

Cheers J

Created on Apr 21, 2020 10:23: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.