Last active
March 11, 2023 05:51
-
-
Save kagarlickij/c7637457254f8b2da4c50c59b688bbf0 to your computer and use it in GitHub Desktop.
This one is for setting CloudWatch Alarms & actions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Import-Module -Name AWSPowerShell | |
$sns = "arn:aws:sns:eu-west-1:851073832283:Monitoring-ops" | |
$instance_id = (Invoke-Restmethod -uri http://169.254.169.254/latest/meta-data/instance-id) | |
$volume_id = (@(get-ec2volume) | Where-Object { $_.Attachments.InstanceId -eq $instance_id}).VolumeId | |
$DimensionInstance = New-Object 'Amazon.CloudWatch.Model.Dimension' | |
$DimensionInstance.Name = 'instance_id' | |
$DimensionInstance.Value = $instance_id | |
$DimensionVolume = New-Object 'Amazon.CloudWatch.Model.Dimension' | |
$DimensionVolume.Name = 'VolumeId' | |
$DimensionVolume.Value = $volume_id | |
Write-CWMetricAlarm ` | |
-AlarmName 'AvailableMemory' ` | |
-AlarmDescription 'Available Memory on instance' ` | |
-ActionsEnabled $True ` | |
-AlarmAction $sns ` | |
-ComparisonOperator 'LessThanThreshold' ` | |
-Dimension $DimensionInstance ` | |
-EvaluationPeriod 1 ` | |
-MetricName 'Available Memory' ` | |
-Namespace 'Windows/Default' ` | |
-Period 300 ` | |
-Statistic 'Average' ` | |
-Threshold 1024 | |
Write-CWMetricAlarm ` | |
-AlarmName 'DiskSpaceCounter' ` | |
-AlarmDescription 'Available disk space on instance' ` | |
-ActionsEnabled $True ` | |
-AlarmAction $sns ` | |
-ComparisonOperator 'LessThanThreshold' ` | |
-Dimension $DimensionInstance ` | |
-EvaluationPeriod 1 ` | |
-MetricName 'Available DiskSpace' ` | |
-Namespace 'Windows/Default' ` | |
-Period 300 ` | |
-Statistic 'Average' ` | |
-Threshold 10240 | |
Write-CWMetricAlarm ` | |
-AlarmName 'NetworkQueueCounter' ` | |
-AlarmDescription 'Network queue on instance' ` | |
-ActionsEnabled $True ` | |
-AlarmAction $sns ` | |
-ComparisonOperator 'GreaterThanOrEqualToThreshold' ` | |
-Dimension $DimensionInstance ` | |
-EvaluationPeriod 1 ` | |
-MetricName 'Network Queue' ` | |
-Namespace 'Windows/Default' ` | |
-Period 300 ` | |
-Statistic 'Average' ` | |
-Threshold 3 | |
Write-CWMetricAlarm ` | |
-AlarmName 'VolumeQueueLength' ` | |
-AlarmDescription 'VolumeQueueLength on disk' ` | |
-ActionsEnabled $True ` | |
-AlarmAction $sns ` | |
-ComparisonOperator 'GreaterThanThreshold' ` | |
-Dimension $DimensionVolume ` | |
-EvaluationPeriod 1 ` | |
-MetricName 'VolumeQueueLength' ` | |
-Namespace 'AWS/EBS' ` | |
-Period 300 ` | |
-Statistic 'Average' ` | |
-Threshold 3 | |
Write-CWMetricAlarm ` | |
-AlarmName 'BurstBalance' ` | |
-AlarmDescription 'BurstBalance for disk' ` | |
-ActionsEnabled $True ` | |
-AlarmAction $sns ` | |
-ComparisonOperator 'LessThanThreshold' ` | |
-Dimension $DimensionVolume ` | |
-EvaluationPeriod 1 ` | |
-MetricName 'BurstBalance' ` | |
-Namespace 'AWS/EBS' ` | |
-Period 300 ` | |
-Statistic 'Average' ` | |
-Threshold 20 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment