Created
December 19, 2014 10:27
-
-
Save tatsuru/2d67e5b8cb32b4acfd79 to your computer and use it in GitHub Desktop.
Theschwartz job count plugin for Mackerel
This file contains hidden or 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 | |
usage() { | |
echo "Usage: $0 [-m METRIC_NAME] [-u USER] [-p PASSWORD] [-d DATABASE] [-h]" | |
} | |
METRIC_NAME=theschwartz.count | |
DBUSER=root | |
DBPASS= | |
DATABASE=theschwartz | |
while getopts m:u:p:d:h OPT | |
do | |
case $OPT in | |
h) usage && exit 0 ;; | |
m) METRIC_NAME=$OPTARG ;; | |
u) DBUSER=$OPTARG ;; | |
p) PASSWORD=$OPTARG ;; | |
d) DATABASE=$OPTARG ;; | |
esac | |
done | |
shift $(($OPTIND - 1)) | |
MYSQL="mysql --skip-column-names -u${DBUSER} ${DATABASE}" | |
[ -z $PASSWORD ] || MYSQL="${MYSQL} -p${PASSWORD}" | |
SQL="select funcname, count(jobid) from job right join funcmap using(funcid) group by funcmap.funcid;" | |
now=$(date +%s) | |
$MYSQL -e "$SQL" | while read job count; do | |
echo -e "${METRIC_NAME}.${job//::/_}\t${count}\t${now}" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment