Skip to content

Instantly share code, notes, and snippets.

@avvi00
Last active January 10, 2018 01:02
Show Gist options
  • Save avvi00/cc095e250001399ef400087738b19f45 to your computer and use it in GitHub Desktop.
Save avvi00/cc095e250001399ef400087738b19f45 to your computer and use it in GitHub Desktop.
Get EC2 cloudwatch metric for instance in powershell
enum MetricStat {
Minimum
Maximum
Average
SampleCount
Sum
}
$metricName = 'CPUCreditBalance'
$instance = 'zzzzzzzzzzz'
$stat = [MetricStat]::Average
$start = [datetime]::Parse('2018-01-01')
$end = [DateTime]::Parse('2018-01-09')
$period = 3600
$stat = Get-CWMetricStatistic -Dimension @{'Name'='InstanceId';'Value'= $instance} -MetricName $metricName -Statistic $stat.ToString() -StartTime $start -EndTime $end -Period $period -Namespace 'AWS/EC2'
$stat.Datapoints | Select Timestamp, Average | Sort-object Timestamp
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment