Last active
March 1, 2023 08:30
-
-
Save myh-st/c6e96b08418ea868a5bc77d4da16e80d to your computer and use it in GitHub Desktop.
Revisions
-
myh-st revised this gist
Mar 1, 2023 . 1 changed file with 0 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -37,8 +37,6 @@ DATA=$(aws cloudwatch get-metric-data \ --output 'text') # Calculate the SLA percentage SUM=$(echo $DATA | tr ' ' '\n' | awk '{sum += $1} END {print sum}') #echo "SUM=$SUM" TOTAL=$(echo $DATA | tr ' ' '\n' | wc -l) -
myh-st created this gist
Mar 1, 2023 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,50 @@ #!/bin/bash INSTANCE_ID="i-0axxxxxxxxxx" NAMESPACE="AWS/EC2" METRIC_NAME="StatusCheckFailed_Instance" START_TIME=$(date -u -d '30 day ago' +%Y-%m-%dT%H:%M:%SZ) END_TIME=$(date -u +%Y-%m-%dT%H:%M:%SZ) AWS_PROFILE=my_profile # Retrieve the metric data DATA=$(aws cloudwatch get-metric-data \ --metric-data-queries '[ { "Id": "m1", "MetricStat": { "Metric": { "Namespace": "'"$NAMESPACE"'", "MetricName": "'"$METRIC_NAME"'", "Dimensions": [ { "Name": "InstanceId", "Value": "'"$INSTANCE_ID"'" } ] }, "Period": 300, "Stat": "Maximum" }, "ReturnData": true } ]' \ --start-time "$START_TIME" \ --end-time "$END_TIME" \ --scan-by 'TimestampDescending' \ --query 'MetricDataResults[0].Values[]' \ --profile "$AWS_PROFILE" \ --output 'text') # Calculate the SLA percentage # SLA = (1 - (sum of all values) / (total number of values)) * 100 SUM=$(echo $DATA | tr ' ' '\n' | awk '{sum += $1} END {print sum}') #echo "SUM=$SUM" TOTAL=$(echo $DATA | tr ' ' '\n' | wc -l) #echo "TOTAL=$TOTAL" SLA=$(echo "scale=2; (100 * ($SUM * 5 - 43200)) / 43200" | bc | awk '{print ($1 < 0) ? -$1 : $1}' ) echo "SLA=$SLA" # Print the result echo "SLA for $METRIC_NAME on instance $INSTANCE_ID over the last 30 days: $SLA%"