rds_slow_log 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in rds_slow_log.gemspec
4
+ gemspec
@@ -0,0 +1,2 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rds_slow_log/slow_log'
4
+
5
+ if ARGV.length == 2
6
+ RdsSlowLog.print_slow_log ARGV[0], ARGV[1]
7
+ else
8
+ puts "Usage: #{$0} HOSTNAME USERNAME"
9
+ end
10
+
11
+
@@ -0,0 +1,45 @@
1
+ require 'active_record'
2
+ require 'highline/import'
3
+
4
+ module RdsSlowLog
5
+ class SlowLog < ActiveRecord::Base
6
+ set_table_name 'slow_log'
7
+
8
+ def query_time
9
+ time_parse query_time_before_type_cast
10
+ end
11
+ def lock_time
12
+ time_parse lock_time_before_type_cast
13
+ end
14
+ def to_s
15
+ <<EOS
16
+ # Time: #{start_time.strftime('%y%m%d %H:%M:%S')}
17
+ # User@Host: #{user_host}
18
+ # Query_time: #{query_time} Lock_time: #{lock_time} Rows_sent: #{rows_sent} Rows_examined: #{rows_examined}
19
+ #{sql_text};
20
+ EOS
21
+ end
22
+
23
+ def self.print_all
24
+ find(:all, :order => :start_time).each do |query|
25
+ puts query
26
+ end
27
+ end
28
+
29
+ private
30
+ def time_parse string
31
+ hours, minutes, seconds = string.to_s.split(/:/)
32
+ hours.to_i * 60 * 60 + minutes.to_i * 60 + seconds.to_i
33
+ end
34
+ end
35
+ def self.print_slow_log hostname, username
36
+ password = ask("Password: ") {|q| q.echo = false}
37
+ ActiveRecord::Base.establish_connection :adapter => 'mysql',
38
+ :database => 'mysql',
39
+ :hostname => hostname,
40
+ :username => username,
41
+ :password => password
42
+ SlowLog.print_all
43
+ end
44
+ end
45
+
@@ -0,0 +1,3 @@
1
+ module RdsSlowLog
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "rds_slow_log/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "rds_slow_log"
7
+ s.version = RdsSlowLog::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["John Hawthorn"]
10
+ s.email = ["john.hawthorn@gmail.com"]
11
+ s.homepage = ""
12
+ s.summary = %q{Prints the MySQL slow query log from an RDS database}
13
+ s.description = %q{Prints the MySQL slow query log from an Amazon RDS database}
14
+
15
+ s.rubyforge_project = "rds_slow_log"
16
+
17
+ s.files = `git ls-files`.split("\n")
18
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
+ s.require_paths = ["lib"]
21
+ end
metadata ADDED
@@ -0,0 +1,72 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rds_slow_log
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - John Hawthorn
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-07-30 00:00:00 Z
19
+ dependencies: []
20
+
21
+ description: Prints the MySQL slow query log from an Amazon RDS database
22
+ email:
23
+ - john.hawthorn@gmail.com
24
+ executables:
25
+ - rds_slow_log
26
+ extensions: []
27
+
28
+ extra_rdoc_files: []
29
+
30
+ files:
31
+ - .gitignore
32
+ - Gemfile
33
+ - Rakefile
34
+ - bin/rds_slow_log
35
+ - lib/rds_slow_log/slow_log.rb
36
+ - lib/rds_slow_log/version.rb
37
+ - rds_slow_log.gemspec
38
+ homepage: ""
39
+ licenses: []
40
+
41
+ post_install_message:
42
+ rdoc_options: []
43
+
44
+ require_paths:
45
+ - lib
46
+ required_ruby_version: !ruby/object:Gem::Requirement
47
+ none: false
48
+ requirements:
49
+ - - ">="
50
+ - !ruby/object:Gem::Version
51
+ hash: 3
52
+ segments:
53
+ - 0
54
+ version: "0"
55
+ required_rubygems_version: !ruby/object:Gem::Requirement
56
+ none: false
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ hash: 3
61
+ segments:
62
+ - 0
63
+ version: "0"
64
+ requirements: []
65
+
66
+ rubyforge_project: rds_slow_log
67
+ rubygems_version: 1.8.6
68
+ signing_key:
69
+ specification_version: 3
70
+ summary: Prints the MySQL slow query log from an RDS database
71
+ test_files: []
72
+