New Question
 
 
PRTG Network Monitor

Intuitive to Use.
Easy to manage.

200.000 administrators have chosen PRTG to monitor their network. Find out how you can reduce cost, increase QoS and ease planning, as well.

Free PRTG
Download >>

 

What is this?

This knowledgebase contains questions and answers about PRTG Network Monitor and network monitoring in general. You are invited to get involved by asking and answering questions!

Learn more

 

Top Tags


View all Tags


Monitoring Hyper-V Replication

Votes:

0

Your Vote:

Up

Down

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 by  Peter Frentin (0) 1



Best Answer

Accepted Answer

Votes:

0

Your Vote:

Up

Down

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 by  victorlclopes (50) 1

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



13 Replies

Votes:

0

Your Vote:

Up

Down

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

Your Vote:

Up

Down

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 by  rhyse (77) 1 1

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



Votes:

0

Your Vote:

Up

Down

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 by  ServerProtector (0)



Votes:

0

Your Vote:

Up

Down

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

Your Vote:

Up

Down

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 by  ServerProtector (0)

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



Votes:

0

Your Vote:

Up

Down

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

Your Vote:

Up

Down

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 by  uebektas (0)



Votes:

0

Your Vote:

Up

Down

# 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 by  elemer82 (0)

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



Votes:

0

Your Vote:

Up

Down

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

Created on Jan 27, 2016 10:49:41 AM by  CFU (0)



Votes:

0

Your Vote:

Up

Down

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 by  polskifacet (0) 1

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



Votes:

0

Your Vote:

Up

Down

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 by  Mark Underhill (0)



Accepted Answer

Votes:

0

Your Vote:

Up

Down

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 by  victorlclopes (50) 1

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



Votes:

0

Your Vote:

Up

Down

@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]



Please log in or register to enter your reply.


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.