Home
%3CLINGO-SUB%20id%3D%22lingo-sub-382101%22%20slang%3D%22en-US%22%3EMeasuring%20Replication%20Health%20in%20a%20cluster%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-382101%22%20slang%3D%22en-US%22%3E%0A%20%26lt%3Bmeta%20http-equiv%3D%22Content-Type%22%20content%3D%22text%2Fhtml%3B%20charset%3DUTF-8%22%20%2F%26gt%3B%3CSTRONG%3E%20First%20published%20on%20TECHNET%20on%20Dec%2030%2C%202013%20%3C%2FSTRONG%3E%20%3CBR%20%2F%3E%3CP%3EAs%20part%20of%20running%20a%20mini-scale%20run%20in%20my%20lab%2C%20I%20had%20to%20frequently%20monitor%20the%20replication%20health%20and%20also%20note%20down%20the%20replication%20statistics.%20The%20statistics%20is%20available%20by%20by%20right%20clicking%20on%20the%20VM%20(in%20the%20Hyper-V%20Manager%20or%20Failover%20Cluster%20Manager)%20and%20choosing%20the%20%3CSTRONG%3E%20Replication%20%3C%2FSTRONG%3E%20submenu%20and%20clicking%20on%20the%20%3CSTRONG%3E%20View%20Replication%20Health%E2%80%A6%20%3C%2FSTRONG%3E%20option.%3C%2FP%3E%0A%20%20%3CP%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F96924i8ABE86C1BA5EEEF2%22%20%2F%3E%3C%2FP%3E%0A%20%20%3CP%3EClicking%20on%20the%20above%20option%2C%20displays%20the%20replication%20statistics%20which%20I%20am%20looking%20for.%3C%2FP%3E%0A%20%20%3CP%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F96925i5BC1D1AA68356598%22%20%2F%3E%3C%2FP%3E%0A%20%20%3CP%3EClicking%20on%20the%20%E2%80%98Reset%20Statistics%E2%80%99%20clears%20the%20statistics%20collected%20so%20far%20and%20resets%20the%20start%20(%E2%80%9CFrom%20time%E2%80%9D%20field)%20time.%3C%2FP%3E%0A%20%20%3CP%3EIn%20a%20large%20deployment%2C%20it%E2%80%99s%20not%20practical%20to%20right%20click%20on%20each%20VM%20to%20get%20the%20health%20statistics.%26nbsp%3B%20Hyper-V%20PowerShell%20cmdlets%20help%20in%20simplifying%20the%20task.%20I%20had%20two%20requirements%3A%3C%2FP%3E%0A%20%20%3CUL%3E%0A%20%20%20%3CLI%3ERequirement%20%231%3A%20Get%20a%20report%20of%20the%20average%20size%20of%20the%20log%20files%20which%20were%20being%20sent%20during%20the%20VMs%20replication%20interval%3C%2FLI%3E%0A%20%20%20%3CLI%3ERequirement%20%232%3A%20Snap%20all%20the%20VMs%20replication%20statistics%20to%20the%20same%20start%20time%20(%E2%80%9CFrom%20time%E2%80%9D)%20field%20and%20reset%20the%20statistics%3C%2FLI%3E%0A%20%20%3C%2FUL%3E%0A%20%20%3CP%3E%3CSTRONG%3EMeasure-VMReplication%20%3C%2FSTRONG%3E%20provides%20the%20replication%20statistics%20for%20each%20of%20the%20replicating%20VMs.%20As%20I%20am%20only%20interested%20in%20the%20average%20replication%20size%2C%20the%20following%20cmdlet%20provides%20the%20required%20information.%3C%2FP%3E%0A%20%20%3CDIV%20id%3D%22codeSnippetWrapper%22%3EMeasure-VMReplication%20%7C%20select%20VMName%2CAvgReplSize%3C%2FDIV%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3ELike%20most%20of%20the%20other%20PowerShell%20cmdlets%20Measure-VMReplication%20takes%20the%20computer%20name%20as%20an%20input.%20To%20get%20the%20replication%20stats%20for%20all%20the%20VMs%20in%20the%20cluster%2C%20I%20would%20need%20to%20enumerate%20the%20nodes%20of%20the%20cluster%20and%20pipe%20the%20output%20to%20this%20cmdlet.%20The%20%3CSTRONG%3E%20Get-ClusterNode%20%3C%2FSTRONG%3E%20is%20used%20to%20get%20the%20nodes%20of%20the%20cluster.%3C%2FP%3E%0A%20%20%3CDIV%20id%3D%22codeSnippetWrapper%22%3E%0A%20%20%20%3CDIV%20id%3D%22codeSnippet%22%3E%24ClusterName%20%3D%20%22%3CNAME%20of%3D%22%22%20your%3D%22%22%20cluster%3D%22%22%3E%22Get-ClusterNode%20-Cluster%20%24ClusterName%3C%2FNAME%3E%3C%2FDIV%3E%0A%20%20%3C%2FDIV%3E%3CBR%20%2F%3E%3CP%3EWe%20can%20pipe%20the%20output%20of%20each%20node%20of%20the%20cluster%20and%20the%20replication%20health%20of%20the%20VMs%20present%20on%20that%20node%3C%2FP%3E%3CBR%20%2F%3E%3CDIV%20id%3D%22codeSnippetWrapper%22%3E%3CBR%20%2F%3E%3CDIV%20id%3D%22codeSnippet%22%3EGet-ClusterNode%20-Cluster%20%24ClusterName%20%7C%20foreach-object%20%7BMeasure-VMReplication%20-ComputerName%20%24_%20%7C%20Select%20VMName%2C%20AvgReplSize%2C%20PrimaryServerName%2C%20CurrentReplicaServerName%20%7C%20ft%7D%3C%2FDIV%3E%0A%20%20%3C%2FDIV%3E%3CBR%20%2F%3E%3CP%3E%3C%2FP%3E%3CBR%20%2F%3E%3CP%3ERequirement%20%231%20is%20met%2C%20now%20let%E2%80%99s%20look%20at%20requirement%20%232.%20To%20snap%20all%20the%20replicating%20VMs%20statistics%20to%20a%20common%20start%20time%2C%20I%20used%20the%20%3CSTRONG%3E%20Reset-VMReplicationStatistics%20%3C%2FSTRONG%3E%20which%20takes%20the%20VMName%20as%20an%20input.%20However%20if%20Reset-VMReplicationStatistics%20is%20used%20on%20a%20non-replicating%20VM%2C%20the%20cmdlet%20errors%20out%20with%20the%20following%20error%20message%3A%3C%2FP%3E%3CBR%20%2F%3E%3CDIV%20id%3D%22codeSnippetWrapper%22%3E%3CBR%20%2F%3E%3CDIV%20id%3D%22codeSnippet%22%3EReset-VMReplicationStatistics%20%3A%20'Reset-VMReplicationStatistics'%20is%20not%20applicable%20on%20virtual%20machine%20'IOMeterBase'.The%20name%20of%20the%20virtual%20machine%20is%20IOMeterBase%20and%20its%20ID%20is%20c1922e67-7a8b-4f36-a868-5174e7b6821a.At%20line%3A1%20char%3A1%2B%20Reset-VMReplicationStatistics%20-vmname%20IOMeterBase%2B%20~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~%20%2B%20CategoryInfo%20%3A%20InvalidOperation%3A%20(Microsoft.Hyper...l.VMReplication%3AVMReplication)%20%5BReset-VMReplicationStatistics%5D%2C%20VirtualizationOperationFailedException%20%2B%20FullyQualifiedErrorId%20%3A%20InvalidOperation%2CMicrosoft.HyperV.PowerShell.Commands.ResetVMReplicationStatisticsCommand%3C%2FDIV%3E%0A%20%20%3C%2FDIV%3E%3CBR%20%2F%3E%3CP%3E%3C%2FP%3E%3CBR%20%2F%3E%3CP%3EIt%E2%80%99s%20a%20touch%20messy%20and%20to%20address%20the%20issue%2C%20we%20would%20need%20to%20isolate%20the%20replicating%20VMs%20in%20a%20given%20server.%20This%20can%20be%20done%20by%20querying%20only%20for%20those%20VMs%20whose%20%3CSTRONG%3E%20ReplicationMode%20%3C%2FSTRONG%3E%20is%20set%20(to%20either%20Primary%20or%20Replica).%20The%20output%20of%20%3CSTRONG%3E%20Get-VM%20%3C%2FSTRONG%3E%20is%20shown%20below%3C%2FP%3E%3CBR%20%2F%3E%3CDIV%20id%3D%22codeSnippetWrapper%22%3E%3CBR%20%2F%3E%3CDIV%20id%3D%22codeSnippet%22%3EPS%20C%3A%5C%26gt%3B%20get-vm%20%7C%20select%20vmname%2C%20ReplicationMode%20%7C%20fl%26nbsp%3BVMName%20%3A%20Cluster22-TPCC3ReplicationMode%20%3A%20Primary%26nbsp%3BVMName%20%3A%20IOMeterBaseReplicationMode%20%3A%20None%3C%2FDIV%3E%0A%20%20%3C%2FDIV%3E%3CBR%20%2F%3E%3CP%3ECluster22-TPCC3%20is%20a%20replicating%20VM%20(Primary%20VM)%20while%20replication%20has%20not%20been%20enabled%20on%20IOMeterBase%20VM.%20Putting%20things%20together%2C%20to%20get%20all%20the%20replicating%20VMs%20in%20the%20cluster%20use%20the%20Get-VM%20cmdlet%20and%20filter%20on%20ReplicationMode%20(Primary%20or%20Replica.%20You%20could%20also%20use%20the%20not-equal%20to%20operation%20get%20both%20primary%20and%20replica%20VMs)%3C%2FP%3E%3CBR%20%2F%3E%3CDIV%20id%3D%22codeSnippetWrapper%22%3E%3CBR%20%2F%3E%3CDIV%20id%3D%22codeSnippet%22%3EGet-ClusterNode%20-Cluster%20%24ClusterName%20%7C%20ForEach-Object%20%7BGet-VM%20-ComputerName%20%24_%20%7C%20Where-Object%20%7B%24_.ReplicationMode%20-eq%20%22Primary%22%7D%7D%3C%2FDIV%3E%0A%20%20%3C%2FDIV%3E%3CBR%20%2F%3E%3CP%3E%3C%2FP%3E%3CBR%20%2F%3E%3CP%3ETo%20reset%20the%20statistics%2C%20pipe%20the%20above%20cmdlet%20to%20Reset-VMReplicationStatistics%3C%2FP%3E%3CBR%20%2F%3E%3CDIV%20id%3D%22codeSnippetWrapper%22%3E%3CBR%20%2F%3E%3CDIV%20id%3D%22codeSnippet%22%3EPS%20C%3A%5C%26gt%3B%20Get-ClusterNode%20-Cluster%20%24ClusterName%20%7C%20ForEach-Object%20%7BGet-VM%20-ComputerName%20%24_%20%7C%20Where-Object%20%7B%24_.ReplicationMode%20-eq%20%22Primary%22%7D%20%7C%20Reset-VMReplicationStatistics%7D%3C%2FDIV%3E%0A%20%20%3C%2FDIV%3E%3CBR%20%2F%3E%3CP%3E%3C%2FP%3EWasn%E2%80%99t%20that%20a%20lot%20easier%20than%20right%20clicking%20on%20each%20VM%20in%20your%20cluster%20and%20clicking%20on%20the%20%E2%80%98Reset%20Statistics%E2%80%99%20button%3F%20%3A)%3C%2Fimg%3E%3C%2FLINGO-BODY%3E%3CLINGO-TEASER%20id%3D%22lingo-teaser-382101%22%20slang%3D%22en-US%22%3EFirst%20published%20on%20TECHNET%20on%20Dec%2030%2C%202013%20As%20part%20of%20running%20a%20mini-scale%20run%20in%20my%20lab%2C%20I%20had%20to%20frequently%20monitor%20the%20replication%20health%20and%20also%20note%20down%20the%20replication%20statistics.%3C%2FLINGO-TEASER%3E%3CLINGO-LABS%20id%3D%22lingo-labs-382101%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3Ehvr%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3Ehyper%20v%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3Ehyper%20v%20replica%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E
Not applicable
First published on TECHNET on Dec 30, 2013

As part of running a mini-scale run in my lab, I had to frequently monitor the replication health and also note down the replication statistics. The statistics is available by by right clicking on the VM (in the Hyper-V Manager or Failover Cluster Manager) and choosing the Replication submenu and clicking on the View Replication Health… option.

Clicking on the above option, displays the replication statistics which I am looking for.

Clicking on the ‘Reset Statistics’ clears the statistics collected so far and resets the start (“From time” field) time.

In a large deployment, it’s not practical to right click on each VM to get the health statistics.  Hyper-V PowerShell cmdlets help in simplifying the task. I had two requirements:

  • Requirement #1: Get a report of the average size of the log files which were being sent during the VMs replication interval
  • Requirement #2: Snap all the VMs replication statistics to the same start time (“From time”) field and reset the statistics

Measure-VMReplication provides the replication statistics for each of the replicating VMs. As I am only interested in the average replication size, the following cmdlet provides the required information.

Measure-VMReplication | select VMName,AvgReplSize

Like most of the other PowerShell cmdlets Measure-VMReplication takes the computer name as an input. To get the replication stats for all the VMs in the cluster, I would need to enumerate the nodes of the cluster and pipe the output to this cmdlet. The Get-ClusterNode is used to get the nodes of the cluster.

$ClusterName = "<Name of your cluster>"Get-ClusterNode -Cluster $ClusterName

We can pipe the output of each node of the cluster and the replication health of the VMs present on that node



Get-ClusterNode -Cluster $ClusterName | foreach-object {Measure-VMReplication -ComputerName $_ | Select VMName, AvgReplSize, PrimaryServerName, CurrentReplicaServerName | ft}


Requirement #1 is met, now let’s look at requirement #2. To snap all the replicating VMs statistics to a common start time, I used the Reset-VMReplicationStatistics which takes the VMName as an input. However if Reset-VMReplicationStatistics is used on a non-replicating VM, the cmdlet errors out with the following error message:



Reset-VMReplicationStatistics : 'Reset-VMReplicationStatistics' is not applicable on virtual machine 'IOMeterBase'.The name of the virtual machine is IOMeterBase and its ID is c1922e67-7a8b-4f36-a868-5174e7b6821a.At line:1 char:1+ Reset-VMReplicationStatistics -vmname IOMeterBase+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (Microsoft.Hyper...l.VMReplication:VMReplication) [Reset-VMReplicationStatistics], VirtualizationOperationFailedException + FullyQualifiedErrorId : InvalidOperation,Microsoft.HyperV.PowerShell.Commands.ResetVMReplicationStatisticsCommand


It’s a touch messy and to address the issue, we would need to isolate the replicating VMs in a given server. This can be done by querying only for those VMs whose ReplicationMode is set (to either Primary or Replica). The output of Get-VM is shown below



PS C:\> get-vm | select vmname, ReplicationMode | fl VMName : Cluster22-TPCC3ReplicationMode : Primary VMName : IOMeterBaseReplicationMode : None

Cluster22-TPCC3 is a replicating VM (Primary VM) while replication has not been enabled on IOMeterBase VM. Putting things together, to get all the replicating VMs in the cluster use the Get-VM cmdlet and filter on ReplicationMode (Primary or Replica. You could also use the not-equal to operation get both primary and replica VMs)



Get-ClusterNode -Cluster $ClusterName | ForEach-Object {Get-VM -ComputerName $_ | Where-Object {$_.ReplicationMode -eq "Primary"}}


To reset the statistics, pipe the above cmdlet to Reset-VMReplicationStatistics



PS C:\> Get-ClusterNode -Cluster $ClusterName | ForEach-Object {Get-VM -ComputerName $_ | Where-Object {$_.ReplicationMode -eq "Primary"} | Reset-VMReplicationStatistics}

Wasn’t that a lot easier than right clicking on each VM in your cluster and clicking on the ‘Reset Statistics’ button? :)