Merge lp:~ilyash/percona-toolkit/tcpdump-raw-queries into lp:percona-toolkit/2.1

Proposed by Ilya Sher
Status: Rejected
Rejected by: Daniel Nichter
Proposed branch: lp:~ilyash/percona-toolkit/tcpdump-raw-queries
Merge into: lp:percona-toolkit/2.1
Diff against target: 143 lines (+107/-0)
2 files modified
bin/pt-query-digest (+56/-0)
lib/TcpdumpQueriesPrinter.pm (+51/-0)
To merge this branch: bzr merge lp:~ilyash/percona-toolkit/tcpdump-raw-queries
Reviewer Review Type Date Requested Status
Daniel Nichter Disapprove
Review via email: mp+124624@code.launchpad.net

Description of the change

pt-query-digest: added --type tcpdumpq

Similar to tcpdump but output all queries. No digesting is performed. This can
be useful to reporoduce loads facilitating the replay of the actual queries.

To post a comment you must log in.
Revision history for this message
Daniel Nichter (daniel-nichter) wrote :

Thanks for the branch; it's well-written. I think, however, that there's an existing solution for this:

$ ./pt-query-digest --type tcpdump ../t/lib/samples/tcpdump/tcpdump001.txt --print --no-report

# Time: 090412 09:50:16.805123
# Client: 127.0.0.1:42167
# Thread_id: 4294967296
# Query_time: 0.000274 Lock_time: 0.000000 Rows_sent: 0 Rows_examined: 0
select "hello world" as greeting;

So the output is a little different, but still has the same info. Does this work for you?

Revision history for this message
Ilya Sher (ilyash) wrote :

Hi.
Yes. Thanks!
This should do the trick and simplify parsing of the output:
./pt-query-digest --type tcpdump ../t/lib/samples/tcpdump/tcpdump001.txt
--no-report --filter 'print $event->{host}, ",", $event->{port}, "\n",
$event->{arg}, "\n"'

It was an RTFM fail I guess :) ... and I think I know why:

man pt-query-digest | wc -l
1604

I was looking near tcpdump, maybe an example there would be helpful noting
this could be helpful for replay.

... or maybe pt-query-digest should be split into several utilities (more
"Unix way"). Currently the pipeline is inside pt-query-digest while it
could be the shell's pipe between smaller utilities. This way it could be
more clear how to do things. In my case I would just cut the pipeline
earlier and just format the events.

Regards,
Ilya

On Fri, Oct 12, 2012 at 6:18 PM, Daniel Nichter <email address hidden> wrote:

> Thanks for the branch; it's well-written. I think, however, that there's
> an existing solution for this:
>
> $ ./pt-query-digest --type tcpdump ../t/lib/samples/tcpdump/tcpdump001.txt
> --print --no-report
>
> # Time: 090412 09:50:16.805123
> # Client: 127.0.0.1:42167
> # Thread_id: 4294967296
> # Query_time: 0.000274 Lock_time: 0.000000 Rows_sent: 0 Rows_examined: 0
> select "hello world" as greeting;
>
> So the output is a little different, but still has the same info. Does
> this work for you?
> --
>
> https://code.launchpad.net/~ilyash/percona-toolkit/tcpdump-raw-queries/+merge/124624
> You are the owner of lp:~ilyash/percona-toolkit/tcpdump-raw-queries.
>

--

Ilya Sher, Coding-Knight LTD.
+972 54 8166121
http://coding-knight.com/

Revision history for this message
Daniel Nichter (daniel-nichter) wrote :

Ah yes, --no-report --filter would allow you to get customized output. Glad that works better for you.

As for breaking the tool up: we plan to simplify it. I don't know if we'll make more tools, but rather just focus this one tool more.

Since the problem has been solved, I'll delete this merge proposal, else it will continue to show up on Launchpad indefinitely I think. :-)

Revision history for this message
Daniel Nichter (daniel-nichter) :
review: Disapprove
Revision history for this message
Daniel Nichter (daniel-nichter) wrote :

Rather than delete it, I just marked it "disapprove", which also removed it from the list of branches ready for review.

Unmerged revisions

394. By Ilya Sher

Added --type tcpdumpq to print all queries found in a tcpdump

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'bin/pt-query-digest'
2--- bin/pt-query-digest 2012-09-14 12:33:52 +0000
3+++ bin/pt-query-digest 2012-09-17 08:59:25 +0000
4@@ -22,6 +22,7 @@
5 Processlist
6 TcpdumpParser
7 MySQLProtocolParser
8+ TcpdumpQueriesPrinter
9 SysLogParser
10 PgLogParser
11 SlowLogParser
12@@ -4112,6 +4113,44 @@
13 # ###########################################################################
14
15 # ###########################################################################
16+# TcpdumpQueriesPrinter package
17+# This package is a copy without comments from the original. The original
18+# with comments and its test file can be found in the Bazaar repository at,
19+# lib/TcpdumpQueriesPrinter.pm
20+# t/lib/TcpdumpQueriesPrinter.t
21+# See https://launchpad.net/percona-toolkit for more information.
22+# ###########################################################################
23+{
24+
25+package TcpdumpQueriesPrinter;
26+use strict;
27+use warnings FATAL => 'all';
28+use English qw(-no_match_vars);
29+use constant PTDEBUG => $ENV{PTDEBUG} || 0;
30+use Data::Dumper;
31+
32+sub new {
33+ my ( $class ) = @_;
34+ my $self = { };
35+ return bless $self, $class;
36+}
37+
38+sub parse_event {
39+ my ( $self, %args ) = @_;
40+ my $event = $args{event};
41+ my @fields = qw(host port user);
42+ print join(',', map { "$event->{$_}" } @fields);
43+ print "\n$event->{arg}\n";
44+ undef $args{event};
45+}
46+
47+1;
48+}
49+# ###########################################################################
50+# End TcpdumpQueriesPrinter package
51+# ###########################################################################
52+
53+# ###########################################################################
54 # SysLogParser package
55 # This package is a copy without comments from the original. The original
56 # with comments and its test file can be found in the Bazaar repository at,
57@@ -13480,6 +13519,7 @@
58 binlog => ['BinaryLogParser'],
59 genlog => ['GeneralLogParser'],
60 tcpdump => ['TcpdumpParser','MySQLProtocolParser'],
61+ tcpdumpq => ['TcpdumpParser','MySQLProtocolParser', 'TcpdumpQueriesPrinter'],
62 memcached => ['TcpdumpParser','MemcachedProtocolParser',
63 'MemcachedEvent'],
64 http => ['TcpdumpParser','HTTPProtocolParser'],
65@@ -16660,6 +16700,22 @@
66 Server-side prepared statements are supported. SSL-encrypted traffic cannot be
67 inspected and decoded.
68
69+=item tcpdumpq
70+
71+Similar to tcpdump but output all queries. No digesting is performed. This can
72+be useful to reporoduce loads facilitating the replay of the actual queries.
73+
74+The output format is 2 lines for each query:
75+
76+ host,port,user
77+ query
78+
79+Host and port specifiy the remote TCP host and port. User is the MySQL user.
80+In order to split the output to files it can be piped for example to the
81+following command:
82+
83+ gawk 'NR % 2 == 1 {f=$0; getline; print >> "thread-" f }'
84+
85 =item memcached
86
87 Similar to tcpdump, but the expected input is memcached packets
88
89=== added file 'lib/TcpdumpQueriesPrinter.pm'
90--- lib/TcpdumpQueriesPrinter.pm 1970-01-01 00:00:00 +0000
91+++ lib/TcpdumpQueriesPrinter.pm 2012-09-17 08:59:25 +0000
92@@ -0,0 +1,51 @@
93+# This program is copyright 2007-2011 Baron Schwartz, 2011 Percona Inc.
94+# Feedback and improvements are welcome.
95+#
96+# THIS PROGRAM IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
97+# WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
98+# MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
99+#
100+# This program is free software; you can redistribute it and/or modify it under
101+# the terms of the GNU General Public License as published by the Free Software
102+# Foundation, version 2; OR the Perl Artistic License. On UNIX and similar
103+# systems, you can issue `man perlgpl' or `man perlartistic' to read these
104+# licenses.
105+#
106+# You should have received a copy of the GNU General Public License along with
107+# this program; if not, write to the Free Software Foundation, Inc., 59 Temple
108+# Place, Suite 330, Boston, MA 02111-1307 USA.
109+# ###########################################################################
110+# TcpdumpParser package
111+# ###########################################################################
112+{
113+# Package: TcpdumpQueriesPrinter
114+# TcpdumpQueriesPrinter prints queries captured from tcpdump.
115+# Outputs 2 lines per query:
116+# host,port,user
117+# query
118+
119+package TcpdumpQueriesPrinter;
120+use strict;
121+use warnings FATAL => 'all';
122+use English qw(-no_match_vars);
123+use constant PTDEBUG => $ENV{PTDEBUG} || 0;
124+use Data::Dumper;
125+
126+sub new {
127+ my ( $class ) = @_;
128+ my $self = { };
129+ return bless $self, $class;
130+}
131+
132+sub parse_event {
133+ my ( $self, %args ) = @_;
134+ my $event = $args{event};
135+ my @fields = qw(host port user);
136+ print join(',', map { "$event->{$_}" } @fields);
137+ print "\n$event->{arg}\n";
138+ undef $args{event};
139+}
140+
141+1;
142+}
143+

Subscribers

People subscribed via source and target branches