Created
December 16, 2020 02:46
-
-
Save missasan/44ff16abe63e7f5e50480a45e79388ab 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 | |
MACKEREL_APIKEY=<YOUR_MACKEREL_APIKEY> | |
SERVICE_NAME="alerts-count" | |
NOW=$(date +%s) | |
ALERT_LOG_FILE="/path/to/logfile" | |
function push_mackerel_alerts_count () { | |
curl -sS \ | |
-X POST \ | |
-H 'X-Api-Key: '${MACKEREL_APIKEY} \ | |
-H 'Content-Type: application/json' \ | |
-d '[{"name":"'$1'","time":'$NOW',"value":'$2'}]' \ | |
https://api.mackerelio.com/api/v0/services/alerts-count/tsdb | |
} | |
cat $ALERT_LOG_FILE | cut -f 4 | sort | uniq -c | while read LINE | |
do | |
TYPE="alerts_count."$(echo "$LINE" | cut -d' ' -f 2) | |
COUNT=$(echo "$LINE" | cut -d' ' -f 1) | |
push_mackerel_alerts_count $TYPE $COUNT | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment