Skip to content

Instantly share code, notes, and snippets.

@bertrandmartel
Created February 11, 2025 13:11
Show Gist options
  • Save bertrandmartel/e862f260f4095026aa83760c5de7ebeb to your computer and use it in GitHub Desktop.
Save bertrandmartel/e862f260f4095026aa83760c5de7ebeb to your computer and use it in GitHub Desktop.
cloudwatch metrics
#!/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