使用percona公司的pt-query-digest分析慢查询日志,分析、统计的结果的比较清晰
#!/bin/sh
slowlog_path=/root/slow_query_log
everyslow=/tmp/everydayslow
##需要下载pt-query-digest
pt_digest=/root/pt-query-digest
start_string=$(grep `date --date="0 days ago" +%y%m%d` ${slowlog_path}|head -1)
start_pos=$(grep -n `date --date="0 days ago" +%y%m%d` ${slowlog_path}|head -1|awk -F: ‘{print $1}‘)
end_pos=$(grep -n `date --date="0 days ago" +%y%m%d` ${slowlog_path}|tail -1|awk -F: ‘{print $1}‘)
print_linecnt=$(expr ${end_pos} - ${start_pos})
##start_string如果不为空,则分析日志
if [ -z "${start_string}" ];
then exit 1
else
grep -i "${start_string}" -A ${print_linecnt} ${slowlog_path} > ${everyslow}
/usr/bin/perl ${pt_digest} ${everyslow} > /tmp/anaslowlog_`date +%Y-%m-%d`
fi
版权声明:本文为博主原创文章,未经博主允许不得转载。
时间: 2024-10-13 07:28:40