Skip to content

Instantly share code, notes, and snippets.

@mago0
Last active March 7, 2018 19:36
Show Gist options
  • Save mago0/d970338fbcfa8277520473a7bf654523 to your computer and use it in GitHub Desktop.
Save mago0/d970338fbcfa8277520473a7bf654523 to your computer and use it in GitHub Desktop.
#!/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