Created
February 11, 2025 13:11
-
-
Save bertrandmartel/e862f260f4095026aa83760c5de7ebeb to your computer and use it in GitHub Desktop.
cloudwatch metrics
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
#!/bin/bash | |
start_date=$(date -d "today -1 hours" -u +'%Y-%m-%dT%H:%M:%SZ') | |
end_date=$(date -d "today +1 hours" -u +'%Y-%m-%dT%H:%M:%SZ') | |
metric_name="metric-status" | |
namespace="metric_namespace" | |
status="success" | |
aws cloudwatch put-metric-data \ | |
--metric-name $metric_name \ | |
--namespace $namespace \ | |
--unit None \ | |
--timestamp $(date -u +'%Y-%m-%dT%H:%M:%SZ') \ | |
--dimensions status=$status \ | |
--value 1 | |
aws cloudwatch get-metric-statistics \ | |
--namespace $namespace \ | |
--metric-name $metric_name \ | |
--start-time $start_date \ | |
--end-time $end_date \ | |
--period 5 \ | |
--statistics "Sum" "Maximum" "Minimum" "Average" "SampleCount" \ | |
--dimensions '[{"Name":"status","Value":"success"}]' | |
# { | |
# "Version": "2012-10-17", | |
# "Statement": [ | |
# { | |
# "Action": [ | |
# "cloudwatch:PutMetricData" | |
# ], | |
# "Effect": "Allow", | |
# "Resource": "*" | |
# } | |
# ] | |
# } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment