代码拉取完成,页面将自动刷新
同步操作将从 mo-shan/script 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
#!/usr/bin/python
#coding : utf-8
#File Name :
#Author : moshan
#Mail : mo_shan@yeah.net
#Created Time: 2019-11-28 10:52:05
#Function :
#########################################################################
# anemometer collection script to gather and digest slow query logs
# this is a quick draft script so please give feedback!
#
# basic usage would be to add this to cron like this:
# */5 * * * * anemometer_collect.sh --interval 15 --history-db-host anemometer-db.example.com
#
# This will have to run as a user which has write privileges to the mysql slow log
#
# Additionally there are two sets of permissions to worry about: The local mysql instance, and the remote digest storage instance
# These are handled through defaults files, just create a file in the: my.cnf format such as:
# [client]
# user=
# password=
#
# use --defaults-file for permissions to the local mysql instance
# and use --history-defaults-file for permissions to the remote digest storage instance
#
#
slow_log= instance_port=3306
digest='/opt/script/pt-query-digest'
IPADDR=$(ip addr show em1 | grep "inet " | awk '{print $2}' | sed 's/\/.*//g')
NOW=$(date +"%F_%H:%M")
history_db_host=slow.db-mljr.com
history_db_port=3308
history_db_name='slow_query_log'
help () {
cat <<EOF
Usage: $0 --interval <seconds>
Options:
--slow-log-file The slow log file location
--instance-port The mysql instance port number
--history-db-host Hostname of anemometer database server
--history-db-port Port of anemometer database server
--history-db-name Database name of anemometer database server (Default slow_query_log)
EOF
}
while test $# -gt 0
do
case $1 in
"--pt-query-digest"|"-d")
digest=$2
shift
;;
"--help")
help
exit 0
;;
"--history-db-host")
history_db_host=$2
shift
;;
"--history-db-port")
history_db_port=$2
shift
;;
"--history-db-name")
history_db_name=$2
shift
;;
"--slow-log-file"|"-s")
slow_log=$2
shift
;;
"--instance-port"|"-p")
instance_port=$2
shift
;;
*)
echo >&2 "Invalid argument: $1"
;;
esac
shift
done
if [ ! -e "${digest}" ];
then
echo "Error: cannot find digest script at: ${digest}"
exit 1
fi
if [ ! -e "${slow_log}" ];
then
echo "Error: cannot find slow log file at: ${slow_log}"
exit 1
fi
qcount=$(grep 'Query_time' $slow_log | wc -l)
if [ -z "$qcount" ] || [ $qcount -eq 0 ]; then
exit 1
fi
echo " Processing log and saving to ${history_db_host}:${history_db_port}/${history_db_name}"
dirpath=/opt/data/mysql_slow_log
mkdir -p $dirpath/$(date +%F)
find $dirpath -mtime +15 -exec rm -rf {} \;
# process the log
"${digest}" --user=anemometer --password=user_anemometer \
--review h="${history_db_host}",P="${history_db_port}",D="$history_db_name",t=global_query_review \
--history h="${history_db_host}",P="${history_db_port}",D="$history_db_name",t=global_query_review_history \
--no-report --limit=0\% \
--filter="\$event->{Bytes} = length(\$event->{arg}) and \$event->{hostname}=\"$IPADDR:$instance_port\" " \
"${slow_log}"
/bin/cp -a -f $slow_log $dirpath/$(date +%F)/slow.log-${instance_port}_${NOW}
> $slow_log
#*/5 * * * * /opt/script/anemometer_collect.sh -s /data/mysql/3321/slow.log -p 3321
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。