Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

关于慢查询获取不到信息 #83

Open
yidazhi opened this issue Jun 28, 2018 · 11 comments
Open

关于慢查询获取不到信息 #83

yidazhi opened this issue Jun 28, 2018 · 11 comments

Comments

@yidazhi
Copy link

yidazhi commented Jun 28, 2018

在两台虚拟机上跑脚本,均无法抓取慢日志里的sql记录到数据库,我的目标数据库和archer所在数据库,均有archer用户,并且all privileges;
慢日志中有内容,并且我也会删除last_analysis_time_$hostname这个文件,但还是抓取不到sql,但是很奇怪的抓取到了慢日志中的show语句:SHOW VARIABLES LIKE 'wait_timeout';

还请大神们帮忙看看

我的脚本配置:
#!/bin/bash
DIR="$( cd "$( dirname "$0" )" && pwd )"
cd $DIR

#config monitor database server 收集日志 配置archer数据库的连接地址
monitor_db_host="192.168.1.159"
monitor_db_port=3306
monitor_db_user="archer"
monitor_db_password="111111"
monitor_db_database="archer"

#config mysql server 被监控机
mysql_host="192.168.1.159" # 和archer主库配置保持一致
mysql_port=3306 # 和archer主库配置保持一致

#config slowqury 被监控机慢日志位置
slowquery_file="/data/mysql/slow.log"
pt_query_digest="/usr/local/bin/pt-query-digest"

#config server_id
hostname="${mysql_host}:${mysql_port}" # 用于archer做筛选

#获取上次分析时间,初始化时请删除last_analysis_time_$hostname文件,可分析全部日志数据
if [ -s last_analysis_time_$hostname ]; then
last_analysis_time=cat last_analysis_time_$hostname
else
last_analysis_time='1000-01-01 00:00:00'
fi

#collect mysql slowquery log into monitor database
#RDS需要增加--no-version-check选项
$pt_query_digest
--user=$monitor_db_user --password=$monitor_db_password --port=$monitor_db_port
--review h=$monitor_db_host,D=$monitor_db_database,t=mysql_slow_query_review
--history h=$monitor_db_host,D=$monitor_db_database,t=mysql_slow_query_review_history
--no-report --limit=100% --charset=utf8
--since "$last_analysis_time"
--filter="$event->{Bytes} = length($event->{arg}) and $event->{hostname}="$hostname" and $event->{client}=$event->{ip} "
$slowquery_file > /tmp/analysis_slow_query.log

echo date +"%Y-%m-%d %H:%M:%S">last_analysis_time_$hostname

@yanlieting
Copy link

我也抓取不到。

@yidazhi
Copy link
Author

yidazhi commented Nov 22, 2018

@yanlieting
下面这3个地方看看:

1、hostname="xxxxxxx:3306" 试试

2、脚本这个也改下
--filter="$event->{Bytes} = length($event->{arg}) and $event->{hostname}="$hostname"" \

3、pt-tools 3.0版本,2点几采集不到

@yanlieting
Copy link

按你指出的几点更改了下,执行报错的。

@yidazhi
Copy link
Author

yidazhi commented Nov 22, 2018

@yanlieting
image
刚才粘贴,好像少粘了一个""

@yanlieting
Copy link

还是不会采集。
我是这样验证的:在archer页面端-sql在线查询,随便执行一个select语句。

配置估计跟你一模一样,我就补贴出来了。

@yanlieting
Copy link

archer和慢日志部署在同一个机器,应该也没关系吧。

@yidazhi
Copy link
Author

yidazhi commented Nov 22, 2018

你应该也设置定时任务了,另外第一次运行脚本时候,看下last_analysis_time_$hostname这个文件,确保一下里面的时间是1000-01-01 00:00:00 。
射手页面的查询是在从库执行的,你确定下脚本是不是在从库执行的,还有慢日志里是否有记录。如果这些都排除了的话,我也不太清楚了。

@yidazhi
Copy link
Author

yidazhi commented Nov 22, 2018

@yanlieting 另外确保运行脚本的服务器的pt工具是3.0版本以上

@yanlieting
Copy link

@yidazhi 是不是只能采集主库的日志?

@yidazhi
Copy link
Author

yidazhi commented Nov 22, 2018

@yanlieting 这个不太清楚,我觉得应该无所谓吧

@frank0826
Copy link

慢查询日志可以正常收集,但是在页面上无法展示慢查询

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants