Advanced Hyper-V Replica Monitoring via #PowerShell #WS12R2 #HyperV #SAPIEN

Tool Updated June 17, 2016 – V2.0 [If any of the virtual machine is in Warning or Critical states, the replication will be resumed automatically without administrator intervention to restore the replication].

Hyper-V Replica can be your lifesaver if a disaster occurs, and at the same time it can be your enemy if you are not monitoring it.

If you have used Hyper-V Replica (of course you did 😉 ), then you will know about the replica status column in Hyper-V Manager console. This is the part of the UI where you can see the state of replica is: Normal, Warning or Critical. A simple interpretation of these states is the following:

  • Normal: No worries, everything is fine! A virtual machine with Normal state if any of the following happen:
    • Less than 20% of replication attempts have been missed.
    • The average latency. That’s important because Hyper-V Replica wants to replicate the Hyper-V Replica Log File (HRL) every 30 sec, 5 min or 15 min. This depends on the replication frequency set.
  • Warning: There have been some problems, but Hyper-V will try to fix them automatically for you. A virtual machine has a warning state if any of the following happen:
    • The initial replica copy or synchronization is not completed.
    • More than 20% of replication cycles have been missed during the current monitoring interval.
    • One hour or more has passed since the last send replica was successfully sent/received.
    • The source virtual machine’s replication is in paused state.
    • Failover has been started, but the reverse replication has not been started.
  • Critical: Sorry, things have gone past the point where Hyper-V can fix them for you, and therefore you need to intervene. A virtual machine has a critical state if any of the following happen:
    • The source primary host is unable to send Hyper-V traffic to the replica host, this could be network or firewall issues.
    • The replication is suspended on the primary or on the replica host.

One of the problem is that things can go really bad if you have Hyper-V replica in a critical state for a long period of time, the (AVHD/AVHDX) differencing disk will grow and can make a big mess on the primary server, and the next thing, you want to know when things go wrong right? because if there is something going wrong in the environment that causes the virtual machines to go into Warning or Critical state – I want to know! And I want to fix it so it does not happen again! I do not want to think that life is good when actually I have a problem to fix Winking smile

As a side note: Hyper-V Replica creates an AVHDX to handle the initial replication of the virtual machine (i.e. getting the first copy of the virtual machine across the replica host). Hyper-V Replica will merge this disk out once it has successfully made a full copy of the virtual machine, virtual hard disk (which can take a while).

So for this reason, I have created a nifty PowerShell script which e-mail the Hyper-V administrator when something goes wrong with Hyper-V Replica in a nice dashboard HTML format.

This script will check first Hyper-V Replica TCP listener on Port 80, because Hyper-V Replica requires HTTP and HTTPS rules to be enabled in Windows Firewall, and then e-mail the Replication State, Replication Mode, the Target frequency of the replica (30 secs, 5 min or 15 min), and how far the replica virtual machine is behind from the primary virtual machine (Delta in min), then the last replication time and the missed replica count used by Virtual Machines which are in Warning and Critical states only in an HTML tabular format to the specified email address. This of course can be used along with a task scheduler to get a notification when something deviating from the normal on a regular basis for monitoring purposes (Please refer to the end of this article to automate the task).

I want to mention that this tool was created using SAPIEN PowerShell Studio 2015 which is a great support when you are creating advanced scripts or GUI Tool Making like the following tool Winking smile.

Get-HyperVReplicaHealthV1.0-04

How to use:

  • Use –PrimHyperV01 parameter, if you want to change the primary Hyper-V host and get info for all primary virtual machines. If not, it will use the Hyper-V host which is defined by default in the script.
  • Use –RepHyperV02 parameter, if you want to change the replica Hyper-V host and get info for all primary virtual machines. If not, it will use the Hyper-V host which is defined by default in the script.
  • Use –ExtHyperV03 parameter, if you want to check the extended Hyper-V Replica host and get info for all primary virtual machines. If not, it will use only the primary and replica Hyper-V hosts.
  • You can run the script on a remote management machine loaded with Hyper-V PowerShell module which is the preferred way, or run it directly on the Hyper-V Host which I don’t recommend.

Examples:

Get-HyperVReplicaHealthV1.0-05

This example will check first the HTTP connectivity to the Primary and Replica Hyper-V server, If both nodes are reachable, then it will look for primary Virtual Machines that are in Warning and Critical state and send you an alert.

Get-HyperVReplicaHealthV1.0-06

This example will check first the HTTP connectivity to the Primary, Replica and Extended Replica Hyper-V Hosts, If all nodes are reachable, then it will look for primary Virtual Machines that are in Warning and Critical state and send you an alert.

Sample Output:

Node is not Reachable Notification!

Get-HyperVReplicaHealthV1.0-01

Warning State Notification!

Get-HyperVReplicaHealthV1.0-02

Critical State Notification!

Get-HyperVReplicaHealthV1.0-03

Last but not least, you can automate the invocation of the Get-HyperVReplicaHealth script using Task Scheduler to run every hour and send you an alert if something goes wrong in Hyper-V Replica. To do this, you can use the Register-ScheduleJob cmdlet. Here’s an example to monitor your Hyper-V Replica Infrastructure every one hour:

You can download a copy of this script from TechNet Gallery here.

This is version 2.0, do you have other scenarios? Please leave your feedback below.

In version 3.0, I will include Hyper-V Replica Broker in a Cluster scenario.

Until then… Enjoy your day!

Cheers,
/Charbel

About Charbel Nemnom 310 Articles
Charbel Nemnom is a Microsoft Cloud Consultant and Technical Evangelist, totally fan of the latest's IT platform solutions, accomplished hands-on technical professional with over 15 years of broad IT Infrastructure experience serving on and guiding technical teams to optimize performance of mission-critical enterprise systems. Excellent communicator adept at identifying business needs and bridging the gap between functional groups and technology to foster targeted and innovative IT project development. Well respected by peers through demonstrating passion for technology and performance improvement. Extensive practical knowledge of complex systems builds, network design and virtualization.

1 Comment

  1. Lovely tool, have to commend you on the job you did here, I was looking for something like this for a while. Unfortunately we are running a clustered environment where the vm’s are replicated between clusters.

    I noticed in your comments are the end that version two would support clusters, May I be so bold as to ask if you have released version 2? if not can you indicate if you are in fact still working on this. Thank you in advance

    And Thank you again for a lovely tool!!

    Kind Regards

Leave a Reply