Skip to content

Commit

Permalink
Merge pull request #1 from vmware/master
Browse files Browse the repository at this point in the history
Pull recent changes
  • Loading branch information
pjorg committed Dec 2, 2016
2 parents 284ba19 + a3bcc1e commit 2e2f027
Show file tree
Hide file tree
Showing 11 changed files with 5,406 additions and 299 deletions.
85 changes: 85 additions & 0 deletions Modules/Get-VMmaxIOPS.psm1
@@ -0,0 +1,85 @@
function Get-VMmaxIOPS {
<#
.SYNOPSIS
Report VM Disk IOPS of VMs
.DESCRIPTION
This Function will Create a VM Disk IOPS Report
.Example
Get-VM TST* | Get-VMmaxIOPS -Minutes 60 | FT -Autosize
.Example
$SampleVMs = Get-VM "TST*"
Get-VMmaxIOPS -VMs $SampleVMs -Minutes 60
.PARAMETER VMs
Specify the VMs
.PARAMETER Minutes
Specify the Minutes to report (10080 is one Week)
.Notes
NAME: Get-VMmaxIOPS.ps1
LASTEDIT: 08/23/2016
VERSION: 1.1
KEYWORDS: VMware, vSphere, ESXi, IOPS
.Link
http://mycloudrevolution.com/
#Requires PS -Version 4.0
#Requires -Modules VMware.VimAutomation.Core, @{ModuleName="VMware.VimAutomation.Core";ModuleVersion="6.3.0.0"}
#>

[CmdletBinding()]
param(
[Parameter(Mandatory=$true, ValueFromPipeline=$True, Position=0)]
[VMware.VimAutomation.ViCore.Impl.V1.Inventory.InventoryItemImpl[]]
$VMs,
[Parameter(Mandatory=$false, Position=1)]
[int] $Minutes = 30
)

Process {

#region: Global Definitions
[int]$TimeRange = "-" + $Minutes
#endregion

#region: Creating Metrics
Write-Debug "Starting to Create Metrics..."
$metrics = "virtualDisk.numberReadAveraged.average","virtualDisk.numberWriteAveraged.average"
$start = (Get-Date).AddMinutes($TimeRange)
$stats = Get-Stat -Stat $metrics -Entity $VMs -Start $start
#endregion

#region: Creating HD-Tab
Write-Debug "Starting to Create HD-Tab..."
$hdTab = @{}
foreach($hd in (Get-Harddisk -VM $VMs)){
$controllerKey = $hd.Extensiondata.ControllerKey
$controller = $hd.Parent.Extensiondata.Config.Hardware.Device | where{$_.Key -eq $controllerKey}
$hdTab[$hd.Parent.Name + "/scsi" + $controller.BusNumber + ":" + $hd.Extensiondata.UnitNumber] = $hd.FileName.Split(']')[0].TrimStart('[')
}
#endregion

#region: Creating Reports
Write-Debug "Starting to Process IOPS Report..."
$reportPerf = @()
$reportPerf = $stats | Group-Object -Property {$_.Entity.Name},Instance | %{
New-Object PSObject -Property @{
VM = $_.Values[0]
Disk = $_.Values[1]
IOPSMax = ($_.Group | `
Group-Object -Property Timestamp | `
%{$_.Group[0].Value + $_.Group[1].Value} | `
Measure-Object -Maximum).Maximum
Datastore = $hdTab[$_.Values[0] + "/"+ $_.Values[1]]
}
}
$reportPerf | Select-Object VM, Disk, Datastore, IOPSMax
#endregion
}
}
63 changes: 37 additions & 26 deletions Modules/Recommend-Sizing.psm1
Expand Up @@ -8,14 +8,15 @@ function Recommend-Sizing {
===========================================================================
Changelog:
2016.11 ver 1.0 Base Release
2016.11 ver 1.1 Optional Stats Collection.
2016.11 ver 1.1 Optional Stats Collection
2016.11 ver 1.2 VM Stats from Realtime Data and new Counters
===========================================================================
External Code Sources:
http://www.lucd.info/2011/04/22/get-the-maximum-iops/
https://communities.vmware.com/thread/485386
===========================================================================
Tested Against Environment:
vSphere Version: 5.5 U2
vSphere Version: 5.5 U2, 6.0
PowerCLI Version: PowerCLI 6.3 R1, PowerCLI 6.5 R1
PowerShell Version: 4.0, 5.0
OS Version: Windows 8.1, Server 2012 R2
Expand All @@ -24,7 +25,7 @@ function Recommend-Sizing {
===========================================================================
.DESCRIPTION
This Function collects Basic vSphere Informations for a Hardware Sizing Recomamndation. Focus is in Compute Ressources.
This Function collects Basic vSphere Informations for a Hardware Sizing Recommandation. Focus is in Compute Ressources.
.Example
Recommend-Sizing -ClusterNames Cluster01, Cluster02 -Stats -StatsRange 60 -Verbose
Expand All @@ -41,7 +42,7 @@ function Recommend-Sizing {
.PARAMETER Stats
Enables Stats Collection.
Warning: At the moment this is only tested and supported with vSphere 5.5!
Warning: At the moment this is only fully tested with vSphere 5.5 and vSphere 6.5!
.PARAMETER StatsRange
Time Range in Minutes for the Stats Collection.
Expand All @@ -55,15 +56,15 @@ function Recommend-Sizing {
param(
[Parameter(Mandatory=$True, ValueFromPipeline=$False, Position=0)]
[Array] $ClusterNames,
[Parameter(Mandatory=$False, ValueFromPipeline=$False, Position=2)]
[Parameter(Mandatory=$False, ValueFromPipeline=$False, Position=1, ParameterSetName = "Stats")]
[switch] $Stats,
[Parameter(Mandatory=$False, ValueFromPipeline=$False, Position=2)]
[Parameter(Mandatory=$False, ValueFromPipeline=$False, Position=2, ParameterSetName = "Stats")]
[int] $StatsRange = 1440

)
Begin {
if ($Stats) {
Write-Warning "Stats Collection enabled.`nAt the moment this is only tested and supported with vSphere 5.5"
Write-Warning "Stats Collection requested.`nAt the moment this is only fully tested with vSphere 5.5 and vSphere 6.5"
[int]$TimeRange = "-" + $StatsRange
}

Expand Down Expand Up @@ -121,30 +122,38 @@ Process {
#endregion

if ($Stats) {
#region: Creating Disk Metrics
Write-Verbose "$(Get-Date -Format G) Create $($Cluster.name) IOPS Metrics..."
$DiskMetrics = "virtualDisk.numberReadAveraged.average","virtualDisk.numberWriteAveraged.average"
$start = (Get-Date).AddMinutes($TimeRange)
$DiskStats = Get-Stat -Stat $DiskMetrics -Entity $ClusterVMsPoweredOn -Start $start -Verbose:$False
Write-Verbose "$(Get-Date -Format G) Create $($Cluster.name) IOPS Metrics completed"
#region: Creating VM Stats
Write-Verbose "$(Get-Date -Format G) Create $($Cluster.name) VM Stats..."
$VMMetrics = "disk.numberwrite.summation","disk.numberread.summation","cpu.usage.average", "mem.usage.average"
$Start = (Get-Date).AddMinutes($TimeRange)
$VMStats = Get-Stat -Realtime -Stat $VMMetrics -Entity $ClusterVMsPoweredOn -Start $Start -Verbose:$False
Write-Verbose "$(Get-Date -Format G) Create $($Cluster.name) VM Stats completed"
#endregion

#region: Creating IOPS Reports
Write-Verbose "$(Get-Date -Format G) Process $($Cluster.name) IOPS Report..."
$reportDiskPerf = @()
$reportDiskPerf = $DiskStats | Group-Object -Property {$_.Entity.Name},Instance | %{
New-Object PSObject -Property @{
IOPSMax = ($_.Group | `
Group-Object -Property Timestamp | `
%{$_.Group[0].Value + $_.Group[1].Value} | `
Measure-Object -Maximum).Maximum
#region: Creating VM Stats Report
Write-Verbose "$(Get-Date -Format G) Process $($Cluster.name) VM Stats Report..."
$ReportVMPerf = @()
$ReportVMPerf = $VMStats | Group-Object -Property {$_.Entity.Name},Instance | %{
New-Object PSObject -Property @{
IOPSWriteAvg = ($_.Group | `
where{$_.MetricId -eq "disk.numberwrite.summation"} | `
Measure-Object -Property Value -Average).Average
IOPSReadAvg = ($_.Group | `
where{$_.MetricId -eq "disk.numberread.summation"} | `
Measure-Object -Property Value -Average).Average
CPUUsageAvg = ($_.Group | `
where{$_.MetricId -eq "cpu.usage.average"} | `
Measure-Object -Property Value -Average).Average
MEMUsageAvg = ($_.Group | `
where{$_.MetricId -eq "mem.usage.average"} | `
Measure-Object -Property Value -Average).Average
}
}
Write-Verbose "$(Get-Date -Format G) Process $($Cluster.name) IOPS Report completed"
Write-Verbose "$(Get-Date -Format G) Process $($Cluster.name) VM Stats Report completed"
#endregion
}
else {
Write-Verbose "$(Get-Date -Format G) Stats Cellocetion skipped..."
Write-Verbose "$(Get-Date -Format G) Stats Collection skipped..."
}

#region: Create VM Disk Space Report
Expand Down Expand Up @@ -194,8 +203,10 @@ Process {
SumVMDiskSpaceGB = [math]::round( ($reportDiskSpace | Measure-Object -Sum -Property CapacityGB).sum, 1 )
SumDatastoreSpaceGB = [math]::round( ($DatastoreReport | Measure-Object -Sum -Property CapacityGB).sum, 1 )
SumDatastoreUsedSpaceGB = [math]::round( ($DatastoreReport | Measure-Object -Sum -Property UsedSpaceGB).sum, 1 )
SumMaxVMIOPS = [math]::round( ($reportDiskPerf | Measure-Object -Sum -Property IOPSMax).sum, 1 )
AverageMaxVMIOPs = [math]::round( ($reportDiskPerf | Measure-Object -Average -Property IOPSMax).Average,1 )
AverageVMIOPSWriteAvg = [math]::round( ($ReportVMPerf | Measure-Object -Average -Property IOPSWriteAvg).Average,1 )
AverageVMIOPSReadAvg = [math]::round( ($ReportVMPerf | Measure-Object -Average -Property IOPSReadAvg).Average,1 )
AverageVMCPUUsageAvg = "$([math]::round( ($ReportVMPerf | Measure-Object -Average -Property CPUUsageAvg).Average,1 )) %"
AverageVMMEMUsageAvg = "$([math]::round( ($ReportVMPerf | Measure-Object -Average -Property MEMUsageAvg).Average,1 )) %"
}
$MyView += $SizingReport
Write-Verbose "$(Get-Date -Format G) Process Global Report completed"
Expand Down
111 changes: 111 additions & 0 deletions Modules/Set-CBT.psm1
@@ -0,0 +1,111 @@
function Set-CBT {
<#
.NOTES
===========================================================================
Created by: Markus Kraus
Twitter: @VMarkus_K
Private Blog: mycloudrevolution.com
===========================================================================
Changelog:
2016.11 ver 1.0 Base Release
===========================================================================
External Code Sources:
http://wahlnetwork.com/2015/12/01/change-block-tracking-cbt-powercli/
===========================================================================
Tested Against Environment:
vSphere Version: 5.5 U2
PowerCLI Version: PowerCLI 6.3 R1
PowerShell Version: 4.0
OS Version: Windows Server 2012 R2
===========================================================================
Keywords vSphere, ESXi, VM, Storage, CBT, Backup
===========================================================================
.DESCRIPTION
This Function enables or disables CBT.
.Example
Get-VN TST* | Set-CBT -DisableCBT
.Example
Get-VN TST* | Set-CBT -EnableCBT
.PARAMETER DisableCBT
Disables CBT for any VMs found with it enabled
.PARAMETER EnableCBT
Enables CBT for any VMs found with it disabled
#Requires PS -Version 4.0
#Requires -Modules VMware.VimAutomation.Core, @{ModuleName="VMware.VimAutomation.Core";ModuleVersion="6.3.0.0"}
#>

[CmdletBinding()]
param(
[Parameter(Mandatory=$True, ValueFromPipeline=$True, Position=0, HelpMessage = "VMs to process")]
[ValidateNotNullorEmpty()]
[VMware.VimAutomation.ViCore.Impl.V1.Inventory.InventoryItemImpl[]] $myVMs,
[Parameter(Mandatory = $False,ValueFromPipeline=$False, Position = 1, HelpMessage = "Enables CBT for any VMs found with it disabled", ParameterSetName = "EnableCBT")]
[ValidateNotNullorEmpty()]
[Switch]$EnableCBT,
[Parameter(Mandatory = $False,ValueFromPipeline=$False, Position = 1, HelpMessage = "Disables CBT for any VMs found with it enabled", ParameterSetName = "DisableCBT")]
[ValidateNotNullorEmpty()]
[Switch]$DisableCBT
)
Process {

$vmconfigspec = New-Object -TypeName VMware.Vim.VirtualMachineConfigSpec
Write-Verbose -Message "Walking through given VMs"
foreach($myVM in $myVMs)
{
if ($DisableCBT -and $myVM.ExtensionData.Config.ChangeTrackingEnabled -eq $true -and $myVM.ExtensionData.Snapshot -eq $null)
{
try
{
Write-Verbose -Message "Reconfiguring $($myVM.name) to disable CBT" -Verbose
$vmconfigspec.ChangeTrackingEnabled = $false
$myVM.ExtensionData.ReconfigVM($vmconfigspec)

if ($myVM.PowerState -eq "PoweredOn" ) {
Write-Verbose -Message "Creating a snapshot on $($myVM.name) to clear CBT file" -Verbose
$SnapShot = New-Snapshot -VM $myVM -Name "CBT Cleanup"

Write-Verbose -Message "Removing snapshot on $($myVM.name)" -Verbose
$SnapShot| Remove-Snapshot -Confirm:$false
}

}
catch
{
throw $myVM
}
}
elseif ($EnableCBT -and $myVM.ExtensionData.Config.ChangeTrackingEnabled -eq $false -and $myVM.ExtensionData.Snapshot -eq $null)
{
Write-Verbose -Message "Reconfiguring $($myVM.name) to enable CBT" -Verbose
$vmconfigspec.ChangeTrackingEnabled = $true
$myVM.ExtensionData.ReconfigVM($vmconfigspec)

if ($myVM.PowerState -eq "PoweredOn" ) {
Write-Verbose -Message "Creating a snapshot on $($myVM.name) to Create CBT file" -Verbose
$SnapShot = New-Snapshot -VM $myVM -Name "CBT Cleanup"

Write-Verbose -Message "Removing snapshot on $($myVM.name)" -Verbose
$SnapShot | Remove-Snapshot -Confirm:$false
}
}
else
{
if ($myVM.ExtensionData.Snapshot -ne $null -and $EnableCBT)
{
Write-Warning -Message "Skipping $($myVM.name) - Snapshots found"
}
elseif ($myVM.ExtensionData.Snapshot -ne $null -and $DisableCBT)
{
Write-Warning -Message "Skipping $($myVM.name) - Snapshots found"
}
}
}

}
}

0 comments on commit 2e2f027

Please sign in to comment.