Last active
March 7, 2018 19:36
-
-
Save mago0/d970338fbcfa8277520473a7bf654523 to your computer and use it in GitHub Desktop.
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 | |
ENV=$1 | |
ENVID=$2 | |
REGION=$3 | |
while true; do | |
CURRENT_SECOND=$(date -d now -u "+%s") | |
START=$(expr $CURRENT_SECOND % 5) | |
if [[ $START -eq 0 ]]; then | |
STATUS=$(curl -s http://localhost/status?json) | |
ACTIVE_PROCS=$(jq '."active processes"' <<<$STATUS) | |
TOTAL_PROCS=$(jq '."total processes"' <<<$STATUS) | |
WORKER_UTILIZATION="$(echo "$ACTIVE_PROCS / $TOTAL_PROCS * 100" | bc -l)" | |
aws cloudwatch put-metric-data \ | |
--region $REGION \ | |
--namespace Core/API_PHP_FPM \ | |
--metric-name WorkerUtilization \ | |
--dimensions role=backend,env=$ENV,envid=$ENVID \ | |
--unit Percent \ | |
--value $(printf %.f $WORKER_UTILIZATION) | |
fi | |
sleep 1 | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment