Skip to content

Instantly share code, notes, and snippets.

@missasan
Created December 16, 2020 02:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save missasan/44ff16abe63e7f5e50480a45e79388ab to your computer and use it in GitHub Desktop.
Save missasan/44ff16abe63e7f5e50480a45e79388ab to your computer and use it in GitHub Desktop.
#!/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