Created
September 2, 2017 00:19
-
-
Save krrrr38/1eb8cdb011304069db4d62396078122c 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 -ex | |
set -ex; | |
if [ $# -lt 4 ]; then | |
echo "Usage: $0 api_key service_name [name value ...]" | |
exit 1; | |
fi | |
API_KEY=$1; shift; | |
SERVICE_NAME=$1; shift; | |
TIME=`date +%s` | |
METRICS=() | |
ARGS=("$@") | |
for i in `seq 0 $(($#/2 - 1))`; do | |
name=${ARGS[$(($i*2))]}; | |
value=${ARGS[$(($i*2+1))]}; | |
METRICS=("{\"name\":\"$name\":,\"value\":$value,\"time\":$TIME}" "${METRICS[@]}") | |
done | |
BODY=$(printf ",%s" "${METRICS[@]}") | |
BODY=${BODY:1} | |
BODY="[$BODY]" | |
curl -XPOST \ | |
-H'Content-Type: application/json' \ | |
-H"X-Api-Key: $API_KEY" \ | |
-d"$BODY" "https://mackerel.io/api/v0/services/$SERVICE_NAME/tsdb" |
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
./mackerel.sh apikey servicename httpstatus `grep $(date '+time:%d/%b/%Y:%H:%m' -d '1 minute ago') /var/log/nginx/diet/access.log | cut -f5 | perl -pe 's/status://' | sort | uniq -c | awk '{print $2 " " $1}' | tr '\n' ' '` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment