Giter Site home page Giter Site logo

myslog's Introduction

myslog

MySQL slow query log parser

Install

gem install myslog

Usage

myslog = MySlog.new

text = <<-EOF
# Time: 111003 14:17:38
# User@Host: root[root] @ localhost []
# Query_time: 0.000270  Lock_time: 0.000097  Rows_sent: 1  Rows_examined: 0
SET timestamp=1317619058;
SELECT * FROM life;
# User@Host: php[php] @  [192.168.10.235]
# Thread_id: 313  Schema: ename_bbs_dx15  Last_errno: 0  Killed: 0
# Query_time: 0.031467  Lock_time: 0.000197  Rows_sent: 0  Rows_examined: 0  Rows_affected: 0  Rows_read: 2
# Bytes_sent: 1243  Tmp_tables: 0  Tmp_disk_tables: 0  Tmp_table_sizes: 0
SET timestamp=1359008764;
SELECT * FROM pre_common_session WHERE sid='vWWzwC' AND CONCAT_WS('.', ip1,ip2,ip3,ip4)='192.168.200.57';
EOF

records = myslog.parse(text)

records is Array of Hash

records[0]
#=> {:date => 2011-10-03 14:17:38 +0900,
#=>  :user => "root[root]",
#=>  :host => "localhost",
#=>  :host_ip => "",
#=>  :query_time => 0.000270,
#=>  :lock_time => 9.7e-05,
#=>  :rows_sent => 1,
#=>  :rows_examined => 0,
#=>  :sql => "SET timestamp=1317619058; SELECT * FROM life;"}
records[1]
#=> {:user => "php[php]",
#=>  :host => "",
#=>  :host_ip => "192.168.10.235",
#=>  :query_time => 0.031467,
#=>  :lock_time => 0.000197,
#=>  :rows_sent => 0,
#=>  :rows_examined => 0,
#=>  :rows_affected => 0,
#=>  :rows_read => 2,
#=>  :thread_id => 313,
#=>  :schema => "ename_bbs_dx15",
#=>  :last_errno => 0,
#=>  :killed => 0,
#=>  :bytes_sent => 1243,
#=>  :tmp_tables => 0,
#=>  :tmp_disk_tables => 0,
#=>  :tmp_table_sizes => 0,
#=>  :sql => "SET timestamp=1359008764; SELECT * FROM pre_common_session WHERE sid='vWWzwC' AND CONCAT_WS('.', ip1,ip2,ip3,ip4)='192.168.200.57';"}

myslog's People

Contributors

ike-dai avatar keepzero avatar onigra avatar yuku avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.