もにかじ2 lt @studio3104

1,195 views

Published on

0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
1,195
On SlideShare
0
From Embeds
0
Number of Embeds
479
Actions
Shares
0
Downloads
7
Comments
0
Likes
2
Embeds 0
No embeds

No notes for slide

もにかじ2 lt @studio3104

  1. 1. Lightning Talk at Monitoring Casual #2監視の勉強会ですが、ちょっとMySQLの話をしますね @studio3104
  2. 2. @studio3104 (Satoshi SUZUKI)-- Perl歴半年くらい-- WEB業界2年目-- 妻、娘、息子います-- ソシャゲ、公式サイト、パチ(スロ)ンコ-- こんなのやってます →→→→→→→-- Perlと心中するらしいです 自己紹介
  3. 3. スロークエリ
  4. 4. とりあえず
  5. 5. EXPLAIN
  6. 6. riywoさん!マジriywoさん!
  7. 7. 僕も作ってみた「out-exec-mysql- slowquery」
  8. 8. MySQL slow_log 1 #!/usr/bin/env perl$ 27 $ tail 2$ 28 unless ( defined $slowlog->{sql} ) {$ 3 use strict;$ 29 print $mp->pack($slowlog);$ 4 use warnings;$ 30 next;$ 5 use Data::Dumper;$ 31 }$ EXPLAIN 6 use DBIx::Handler;$ 7 use JSON::XS;$ 32 $ 33 my $select_statement;$ 8 use Data::MessagePack;$ 34 if ( $slowlog->{sql} =~ /(select[^;]+)/i ) {$ 9$ 35 $select_statement = $1;$ 10 $| = 1;$ 36 }$ 11 $ 37 $ 12 my $mp = Data::MessagePack->new();$ 38 if ( $slowlog->{sql} =~ /^use ([^;]+)/i ) {$ 13 $ 39 $db = ` . $1 . `;$ 14 my $db_user = "root";$ 40 }$ 15 my $db_passwd = "";$ 41 $ 16 my $db_opt = { RaiseError => 0, PrintError => 1 };$ 42 if ( defined $db && defined $select_statement ) {$ 17 my $handler = DBIx::Handler->new( "DBI:mysql: 43 $handler->dbh->do("use $db");$database=information_schema:1 27.0.0.1", $db_user, 44 my $explains = eval { $handler->dbh-$db_passwd, $db_opt );$ >selectall_arrayref( "EXPLAIN $selec t_statement", +{ 18 $ Slice => {} } ); };$ 19 my $db;$ 45 if ( ref $explains eq ARRAY ) {$ 20 my $long_query_time = $handler->dbh- 46 $slowlog->{explain} = $explains;$>selectrow_array($ 47 $slowlog->{database} = $db;$ 21 "SELECT VARIABLE_VALUE FROM 48 }$GLOBAL_VARIABLES WHERE VARIABLE_NAME = 49 }$LONG_Q UERY_TIME");$ 50 $ 22 $handler->dbh->do("SELECT SLEEP 51 print $mp->pack($slowlog);$($long_query_time)");$ 52 }$ 23 $ 24 while ( my $json = <STDIN> ) {$ 25 my $slowlog = eval { decode_json($json); };$ 26 next if ($@);$ store MongoDB
  9. 9. DEMO
  10. 10. Openess is ourdriver forexcellence
  11. 11. 公開したよ!https://github.com/studio3104/out-exec-mysql-slowquery
  12. 12. スーパー宣伝タイム
  13. 13. Lightning Talk at Monitoring Casual #2監視の勉強会ですが、ちょっとMySQLの話をしますね ご清聴ありがとうございました @studio3104

×