vSphere Replication was introduced with vSphere 5.0 and SRM 5.0 providing a way for customers without the ability to leverage storage array replication to utilize Site Recovery Manager (SRM) within their environments as their disaster recovery solution.

With the release of vSphere 5.1 vSphere Replication also became available as a standalone replication solution included with Essentials Plus and higher vSphere license editions. Customers now have the option of deploy vSphere Replication on its own to provide basic per-VM replication for use cases where SRM’s advanced DR orchestration capabilities were not applicable.

As adoption of vSphere Replication is growing amongst the vSphere 5.1 customer base so has the number of requests for ideas, hints and tips on what kind of reporting could be added to provide usage information for the various events that could occur amongst a collection of replicated VM’s.

Some examples would be:

highlight when a given VM violates its RPO

detect when the violated RPO state is restored

compute the time duration for the RPO violation

collate the total amount of data replicated for a given VM over a given time period

The number of customers asking for this kind of information led to this blog being written and the scripts being created in conjunction with Lee Dilworth who is a Principal Systems Engineer with VMware and SRM expert.

In this initial article we have included some scripts that will provide the administrator with a means to produce a csv file that contains (for each replicated VM) a history of its RPO violations, when they started/ended and how long each lasted.

Working with events

PowerCLI has a great cmdlet which allows us to work with vSphere Events, this means we can programmatically display and export the information we need by finding a list of events which have been produced in vSphere. This cmdlet is called Get-VIEvent, more information on its usage can be found here.

Retrieving all vSphere Replication events

With our first example, once connected to the source replication vCenter Server in PowerCLI through the Connect-VIServer cmdlet we can easily pull any events which have been generated by vSphere Replication and export them straight into a CSV file onto the current users desktop by using the following One-Liner:

Get-VIEvent -MaxSamples ([int]::MaxValue) | Where { $_.EventTypeId -match "hbr|rpo" } | Select CreatedTime, FullFormattedMessage, @{Name="VMName";Expression={$_.Vm.Name}} | export-csv -NoTypeInformation -Path ([Environment]::GetFolderPath("Desktop") + "\HBR-RPOEvents.csv")

Example formatted output:

Creating the RPO Report

Now we are able to retrieve the event information for RPO events we can format the data to give us exactly what we needed from the report, again this will output a file to the users desktop, make sure you are connected to the source vCenter server and then run this script:

Write-Host "[$(Get-Date)] Retrieving VMs" $VMs = Get-VM $Results = @() Foreach ($VM in $VMs) { Write-Host "[$(Get-Date)] Retrieving events for $($VM.name)" $Events = Get-VIEvent -MaxSamples ([int]::MaxValue) -Entity $VM Write-Host "[$(Get-Date)] Filtering RPO events for $($VM.name)" $RPOEvents = $Events | where { $_.EventTypeID -match "rpo" } | Where { $_.Vm.Name -eq $VM.Name } | Select EventTypeId, CreatedTime, FullFormattedMessage, @{Name="VMName";Expression={$_.Vm.Name}} | Sort CreatedTime if ($RPOEvents) { $Count = 0 Write-Host "[$(Get-Date)] Finding replication results for $($VM.Name)" do { $details = "" | Select VMName, ViolationStart, ViolationEnd, Mins if ($RPOEvents[$count].EventTypeID -match "Violated") { If (-not $details.Start) { $Details.VMName = $RPOEvents[$Count].VMName $Details.ViolationStart = $RPOEvents[$Count].CreatedTime Do { $Count++ } until (($RPOEvents[$Count].EventTypeID -match "Restored") -or ($Count -gt $RPOEvents.Count)) if ($RPOEvents[$count].EventTypeID -match "Restored") { $details.ViolationEnd = $RPOEvents[$Count].CreatedTime $Time = $details.ViolationEnd - $details.ViolationStart $details.Mins = "{0:N2}" -f $Time.TotalMinutes } Else { $details.ViolationEnd = "No End Date" $details.Mins = "N/A" } } } $Results += $details $Count++ } until ($count -gt $RPOEvents.Count) } } $Results | export-csv -NoTypeInformation -Path ([Environment]::GetFolderPath("Desktop") + "\ViolationReport.csv")

Example formatted output:

-Alan

Share this: Email

Print

Twitter

Facebook

Reddit

