box / Anemometer

Box SQL Slow Query Monitor
Apache License 2.0
1.39k stars 316 forks source link

hostname_max column is empty #181

Open vachanda opened 7 years ago

vachanda commented 7 years ago

Hi,

I'm using pt-query-digest to parse the mysql slow query logs and am trying to visualize the data using anemometer. I run initial DB schema migrations on anemometer, but when I try to run the pt-query-digest command, it fails with the error - DBD::mysql::st execute failed: Column 'hostname_max' cannot be null.

The pt-query-digest command -

pt-query-digest --user=abc --password=abc --database=slow_query_log \
                           --review h=localhost,D=slow_query_log,t=global_query_review \
                           --history h=localhost,D=slow_query_log,t=global_query_review_history \
                           --no-report --limit=0% slow_query.log

I'm running it on mysql version 5.7.12 and percona-toolkit version 2.2.18. Any ideas on how to fix it?

akuzminsky commented 7 years ago

@vachanda , we'll have a look

krzykawski commented 7 years ago

I'm sure vachanda above already has fixed this. For others that are having the same issue, the pt-query-digest command line need the hostname specified as described in https://github.com/box/Anemometer/blob/master/README.md

i.e, my function in my collect script run across all db's is: ` digest() {

    LOG "Running pt-query-digest and saving metrics in database $STOREDB - file: $1"

    pt-query-digest \
    --user=${DBUSER} \
    --password=${DBPASS} \
    --review h=${STOREDB},D=slow_query_log,t=global_query_review,P=${STOREDBPORT} \
    --history h=${STOREDB},D=slow_query_log,t=global_query_review_history,P=${STOREDBPORT} \
    --no-report \
    --limit=0% \
    --filter=" \$event->{Bytes} = length(\$event->{arg}) and \$event->{hostname}=\"$HOSTNAME:$MYPORT\"" $1 >> $SESSIONLOGFILE

EXIT=$?

} `

Note $HOSTNAME and $MYPORT. The latter is picked up from the local my.cnf file like: MYPORT=$(cat /etc/my.cnf|grep port|head -1|sed 's/[^0-9]//g'). The former is a bash default var, but if you're on an older bash, you can populate it like HOSTNAME=$(hostname)

Jonathanliu525 commented 7 years ago

I have the same problem when I use the percona-toolkit 2.2.13,although I specify the host by using --filter=" \$event->{Bytes} = length(\$event->{arg}) and \$event->{hostname}=\"$HOSTNAME\"" I solve it after changing to percona-toolkit 3.0.2. know more about the hostname_max. You can read this

https://www.percona.com/blog/2012/08/28/hidden-columns-of-query_review_history/