Skip to content

Instantly share code, notes, and snippets.

@krymtkts
Created January 23, 2023 03:17
Show Gist options
  • Save krymtkts/4c27de22c99638eccda49eeb79a673ef to your computer and use it in GitHub Desktop.
Save krymtkts/4c27de22c99638eccda49eeb79a673ef to your computer and use it in GitHub Desktop.
generate CloudWatch graph souce for IOPS / Throughput of EBS.
[CmdletBinding()]
param (
[Parameter(Mandatory)]
[ValidateNotNullOrEmpty()]
[string[]]
$VolumeIds,
[Parameter(Mandatory)]
[ValidateNotNullOrEmpty()]
[ValidateSet('IOPS', 'Throughput')]
[string]
$Graph
)
$Symbol = switch ($Graph) {
'IOPS' { 'Ops' }
'Throughput' { 'Bytes' }
Default {}
}
$i = 1
$period = 300
$metrics = New-Object System.Collections.ArrayList
$VolumeIds | ForEach-Object {
$Metrics.Add(@( @{
'expression' = "(m${i}+m$($i+1))/${period}"
'label' = "${Graph} of ${_}"
'id' = "e${i}"
} ))
$Metrics.Add(@(
'AWS/EBS'; "VolumeRead${Symbol}"; 'VolumeId'; $_
@{ 'id' = "m${i}"; 'visible' = $false }
))
$Metrics.Add(@(
'AWS/EBS'; "VolumeWrite${Symbol}"; 'VolumeId'; $_
@{ 'id' = "m$($i+1)"; 'visible' = $false }
))
$i += 2
} | Out-Null
[PSCustomObject]@{
'metrics' = $metrics
'view' = 'timeSeries'
'stacked' = $false
'region' = 'ap-northeast-1'
'stat' = 'Sum'
'period' = $period
'title' = $Graph
} | ConvertTo-Json -Depth 10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment