Created
June 1, 2012 09:01
-
-
Save hatak/2850549 to your computer and use it in GitHub Desktop.
send mail of digest-slowlog
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 | |
GROUP="hoge-service" | |
HOST_MASTER="master" | |
HOST_SLAVE="slave01 slave02 slave03" | |
MAILTO="[email protected]" | |
TMPFILE=/tmp/slow-log.`date "+%s"`.log | |
echo "${GROUP} servers summary" > ${TMPFILE} | |
echo >> ${TMPFILE} | |
## master | |
for TARGET in ${HOST_MASTER} | |
do | |
echo "${TARGET} ----------" >> ${TMPFILE} | |
ssh ${TARGET} "zcat /var/log/mysql/mysqld-slow.log-`date "+%Y%m%d"`.gz" | pt-query-digest >> ${TMPFILE} | |
echo >> ${TMPFILE} | |
done | |
## slave | |
for TARGET in ${HOST_SLAVE} | |
do | |
echo "${TARGET} ----------" >> ${TMPFILE} | |
ssh ${TARGET} "zcat /var/log/mysql/mysqld-slow.log-`date "+%Y%m%d"`.gz" | pt-query-digest >> ${TMPFILE} | |
echo >> ${TMPFILE} | |
done | |
cat ${TMPFILE} | mail -s "Summary of slow-query ${GROUP}" ${MAILTO} | |
rm -f ${TMPFILE} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment