poolboy 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ ZjIwZTBhYWMyNGNjODJiNzg0YzlkYTAxNzdkMTFlNGI4ZTg2YWMzZA==
5
+ data.tar.gz: !binary |-
6
+ NDJhYTcyNTE3NzFlNzUyYjAxOTA2ZmIwZGQ4Yzc1MzRjYzEwZjQ4YQ==
7
+ !binary "U0hBNTEy":
8
+ metadata.gz: !binary |-
9
+ NjQwMWJmNjJmNjUwMTk1ODkzMWQ0NGJkMTdmNGIwZjQ2MzNlMmE3NDAxY2U5
10
+ MGMxNmMzNGQ0OWE4MDUyYTkzYTFhZGI4MWU2Y2VjNzQ1N2E3MTcxM2U4OGY5
11
+ ODcyNTNhODFiZWE2MjU2YmU1ODQ2ZDAyMWY1NzcwNzE2M2M2MzM=
12
+ data.tar.gz: !binary |-
13
+ ODE4MmFhYjEwOWI0MWJjZTBlOTYzODRhMmViNzcxMDk3NGUwZjY2MGRkODlj
14
+ YTRmMGY0MWY4NTA0ZTc5ODRkYWNkMGE3NThhYTY0MmFiM2UxMWNiNDVmM2E3
15
+ NTY3ZDRiZDI2ZDk0ZDA1NzdhNzYzYzRmNDYwYmUzYjk0OWQzMGQ=
data/.gitignore ADDED
@@ -0,0 +1,24 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ coverage
12
+ InstalledFiles
13
+ lib/bundler/man
14
+ pkg
15
+ rdoc
16
+ spec/reports
17
+ test/tmp
18
+ test/version_tmp
19
+ tmp
20
+
21
+ # YARD artifacts
22
+ .yardoc
23
+ _yardoc
24
+ doc/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in poolboy.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Sam
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # Poolboy
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'poolboy'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install poolboy
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ desc "Open an irb session preloaded with this library"
4
+ task :console do
5
+ sh "irb -rubygems -I lib -r poolboy.rb"
6
+ end
data/bin/poolboy ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $:.unshift File.join(File.dirname(__FILE__), *%w[.. lib])
4
+
5
+ require 'poolboy'
data/lib/poolboy/51.rb ADDED
@@ -0,0 +1,38 @@
1
+
2
+ class FiveOne
3
+
4
+ def self.get_stats(mysql_conn)
5
+ results ={}
6
+ results['stats'] = mysql_conn.query("
7
+ SELECT a.psize buffer_pool_mb, b.pageda pages_data,
8
+ c.pagem pages_misc, d.pagef pages_free, e.pagesi page_size
9
+ FROM (SELECT variable_value / 1024 / 1024 psize FROM GLOBAL_VARIABLES WHERE VARIABLE_NAME = 'INNODB_BUFFER_POOL_SIZE') a,
10
+ (SELECT variable_value pageda FROM GLOBAL_STATUS WHERE VARIABLE_NAME = 'INNODB_BUFFER_POOL_PAGES_DATA') b,
11
+ (SELECT variable_value pagem FROM GLOBAL_STATUS WHERE VARIABLE_NAME = 'INNODB_BUFFER_POOL_PAGES_MISC') c,
12
+ (SELECT variable_value pagef FROM GLOBAL_STATUS WHERE VARIABLE_NAME = 'INNODB_BUFFER_POOL_PAGES_FREE') d,
13
+ (SELECT variable_value pagesi FROM GLOBAL_VARIABLES WHERE VARIABLE_NAME = 'INNODB_PAGE_SIZE') e")
14
+
15
+ results['bp'] = mysql_conn.query("
16
+ SELECT `schema` AS db,
17
+ innodb_sys_tables.name AS table_n,
18
+ innodb_sys_indexes.name AS i_name,
19
+ cnt,
20
+ dirty,
21
+ hashed,
22
+ IFNULL(ROUND(cnt * 100 / index_s, 2),0) pct
23
+ FROM (SELECT index_id,
24
+ COUNT(*) cnt,
25
+ SUM(dirty = 1) dirty, SUM(hashed = 1) hashed,
26
+ data_size index_s
27
+ FROM innodb_buffer_pool_pages_index
28
+ GROUP BY index_id) bp
29
+ JOIN innodb_sys_indexes ON bp.index_id = innodb_sys_indexes.id
30
+ JOIN innodb_sys_tables ON innodb_sys_indexes.table_id = innodb_sys_tables.id
31
+ JOIN innodb_index_stats ON innodb_index_stats.table_name = innodb_sys_tables.name
32
+ AND innodb_sys_indexes.name = innodb_index_stats.index_name
33
+ AND innodb_index_stats.table_schema = innodb_sys_tables.SCHEMA ORDER BY cnt DESC
34
+ ")
35
+ return results
36
+ end
37
+
38
+ end
data/lib/poolboy/55.rb ADDED
@@ -0,0 +1,42 @@
1
+ class FiveFive
2
+
3
+ def self.get_stats(mysql_conn)
4
+ results ={}
5
+ results['stats'] = mysql_conn.query("
6
+ SELECT a.psize buffer_pool_mb, b.pageda pages_data, c.pagem pages_misc,
7
+ d.pagef pages_free, e.pagesi page_size
8
+ FROM (SELECT variable_value / 1024 / 1024 psize FROM GLOBAL_VARIABLES WHERE VARIABLE_NAME = 'INNODB_BUFFER_POOL_SIZE') a,
9
+ (SELECT variable_value pageda FROM GLOBAL_STATUS WHERE VARIABLE_NAME = 'INNODB_BUFFER_POOL_PAGES_DATA') b,
10
+ (SELECT variable_value pagem FROM GLOBAL_STATUS WHERE VARIABLE_NAME = 'INNODB_BUFFER_POOL_PAGES_MISC') c,
11
+ (SELECT variable_value pagef FROM GLOBAL_STATUS WHERE VARIABLE_NAME = 'INNODB_BUFFER_POOL_PAGES_FREE') d,
12
+ (SELECT variable_value pagesi FROM GLOBAL_VARIABLES WHERE VARIABLE_NAME = 'INNODB_PAGE_SIZE') e")
13
+
14
+ results['bp'] = mysql_conn.query("
15
+ SELECT `schema` AS db,
16
+ innodb_sys_tables.name AS table_n,
17
+ innodb_sys_indexes.name AS i_name,
18
+ cnt,
19
+ dirty,
20
+ hashed,
21
+ IFNULL(ROUND(cnt * 100 / index_size, 2),0) pct
22
+ FROM (SELECT index_id,
23
+ COUNT(*) cnt,
24
+ SUM(dirty = 1) dirty,
25
+ SUM(hashed = 1) hashed,
26
+ data_size index_size
27
+ FROM innodb_buffer_pool_pages_index
28
+ GROUP BY index_id) bp
29
+ JOIN innodb_sys_indexes
30
+ ON bp.index_id = innodb_sys_indexes.index_id
31
+ JOIN innodb_sys_tables
32
+ ON innodb_sys_indexes.table_id = innodb_sys_tables.table_id
33
+ JOIN innodb_index_stats
34
+ ON innodb_index_stats.table_name = innodb_sys_tables.name
35
+ AND innodb_sys_indexes.name = innodb_index_stats.index_name
36
+ AND innodb_index_stats.table_schema = innodb_sys_tables.SCHEMA
37
+ ORDER BY cnt DESC
38
+ ")
39
+ return results
40
+ end
41
+
42
+ end
@@ -0,0 +1,32 @@
1
+ require 'mysql2'
2
+
3
+ class Mysql
4
+
5
+ def initialize(host, user, pass)
6
+ begin
7
+ @mysql = Mysql2::Client.new(:host => host, :username => user, :password => pass, :database => 'information_schema', :connect_timeout => 2, :symbolize_keys => true)
8
+ rescue Mysql2::Error => e
9
+ puts e
10
+ exit
11
+ end
12
+ end
13
+
14
+ def version
15
+ version = @mysql.query("SHOW VARIABLES LIKE 'version'")
16
+ return version.first[:Value]
17
+ end
18
+
19
+ def query(query)
20
+ begin
21
+ results = @mysql.query(query)
22
+ return results
23
+ rescue Mysql2::Error => e
24
+ puts e
25
+ exit
26
+ end
27
+ end
28
+
29
+ def disconnect()
30
+ @mysql.close
31
+ end
32
+ end
@@ -0,0 +1,42 @@
1
+ require 'curses'
2
+
3
+ class Screen
4
+
5
+ def self.show_message(message)
6
+ @win.setpos(0, 0)
7
+ message['stats'].each do |s|
8
+ pool_size = (s.fetch(:pages_misc).to_i + s.fetch(:pages_data).to_i * s.fetch(:page_size).to_i / 1024 / 1024)
9
+ stats = "Buffer Pool: %s/%sMB Data pages: %s Misc Pages: %s Free pages: %s\n" % [pool_size, s.fetch(:buffer_pool_mb), s.fetch(:pages_data), s.fetch(:pages_misc), s.fetch(:pages_free)]
10
+ @win.addstr(stats)
11
+ end
12
+ names = (@width * 0.23).round()
13
+ stats = (@width * 0.07).round()
14
+ title = "%-#{names}.#{names}s" % "Database" + "%-#{names}.#{names}s" % "Table" + "%-#{names}.#{names}s" % "Index" + "%-#{stats}.#{stats}s" % "Pages" + "%-#{stats}.#{stats}s" % "Dirty" + "%-#{stats}.#{stats}s" % "Hashed" + "%-#{stats}.#{stats}s\n" % "%"
15
+ template = "%{db}%{table_n}%{i_name}%{cnt}%{dirty}%{hashed}%{pct}\n"
16
+ @win.addstr("-" * @win.maxx)
17
+ @win.addstr(title)
18
+ @win.addstr("-" * @win.maxx)
19
+ row_max = @win.maxy - 2
20
+ rows = 2
21
+
22
+ message['bp'].each do |row|
23
+ row[:db] = "%-#{names}.#{names}s" % row.fetch(:db)
24
+ row[:table_n] = "%-#{names}.#{names}s" % row.fetch(:table_n)
25
+ row[:i_name] = "%-#{names}.#{names}s" % row.fetch(:i_name)
26
+ row[:cnt] = "%-#{stats}.#{stats}s" % row.fetch(:cnt)
27
+ row[:dirty] = "%-#{stats}.f" % row.fetch(:dirty)
28
+ row[:hashed] = "%-#{stats}.f" % row.fetch(:hashed)
29
+ row[:pct] = "%-#{stats}.2f" % row.fetch(:pct)
30
+ @win.addstr(template % row)
31
+ rows += 1
32
+ break if rows >= row_max
33
+ end
34
+ @win.refresh
35
+ end
36
+
37
+ def self.open_screen()
38
+ @win = Curses::Window.new(0,0,0,0)
39
+ @width = @win.maxx
40
+ @hight = @win.maxy
41
+ end
42
+ end
@@ -0,0 +1,3 @@
1
+ module Poolboy
2
+ VERSION = "0.0.1"
3
+ end
data/lib/poolboy.rb ADDED
@@ -0,0 +1,62 @@
1
+ require 'poolboy/screen'
2
+ require 'poolboy/mysql'
3
+ require 'poolboy/55'
4
+ require 'poolboy/51'
5
+ require 'optparse'
6
+ require 'yaml'
7
+
8
+ module Poolboy
9
+
10
+ options = {}
11
+ OptionParser.new do |opts|
12
+ opts.on("-h HOST") do |h|
13
+ options[:host] = h
14
+ end
15
+ opts.on("-u USER") do |u|
16
+ options[:user] = u
17
+ end
18
+ opts.on("-p PASSWORD") do |p|
19
+ options[:pass] = p
20
+ end
21
+ end.parse!
22
+
23
+ if options.length < 3
24
+ begin
25
+ config_file = YAML.parse_file(ENV['HOME']+'/.poolboy.yaml').to_ruby
26
+ if not options.has_key?(:host)
27
+ options[:host] = config_file["host"]
28
+ end
29
+ if not options.has_key?(:user)
30
+ options[:user] = config_file["user"]
31
+ end
32
+ if not options.has_key?(:pass)
33
+ options[:pass] = config_file["pass"]
34
+ end
35
+ rescue Errno::ENOENT
36
+ end
37
+ end
38
+
39
+ my_con = Mysql.new(options[:host], options[:user], options[:pass])
40
+ version = my_con::version
41
+ if version[0,3] == '5.1'
42
+ mysql_map = FiveOne
43
+ elsif version[0,3] == '5.5'
44
+ mysql_map = FiveFive
45
+ else
46
+ puts "Incompatible MySQL version. Poolboy is only compatable with Percona Server."
47
+ exit
48
+ end
49
+ screen = Screen
50
+ screen::open_screen()
51
+
52
+ begin
53
+ while true
54
+ results = mysql_map::get_stats(my_con)
55
+ screen::show_message(results)
56
+ sleep(1)
57
+ end
58
+ rescue SystemExit, Interrupt
59
+ exit
60
+ end
61
+
62
+ end
data/poolboy.gemspec ADDED
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'poolboy/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "poolboy"
8
+ spec.version = Poolboy::VERSION
9
+ spec.authors = ["Sam"]
10
+ spec.email = ["sam@ninjapanda.co.uk"]
11
+ spec.description = %q{See the status of your Percona Server buffer pool}
12
+ spec.summary = %q{Poolboy lets you view the data in your buffer pool}
13
+ spec.homepage = "http://www.samlambert.com"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = ["poolboy"]
18
+ spec.default_executable = 'poolboy'
19
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_dependency "mysql2"
23
+ spec.add_development_dependency "bundler", "~> 1.3"
24
+ spec.add_development_dependency "rake"
25
+ end
metadata ADDED
@@ -0,0 +1,100 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: poolboy
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Sam
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-05-31 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: mysql2
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ! '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ! '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '1.3'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '1.3'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ! '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: See the status of your Percona Server buffer pool
56
+ email:
57
+ - sam@ninjapanda.co.uk
58
+ executables:
59
+ - poolboy
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - .gitignore
64
+ - Gemfile
65
+ - LICENSE.txt
66
+ - README.md
67
+ - Rakefile
68
+ - bin/poolboy
69
+ - lib/poolboy.rb
70
+ - lib/poolboy/51.rb
71
+ - lib/poolboy/55.rb
72
+ - lib/poolboy/mysql.rb
73
+ - lib/poolboy/screen.rb
74
+ - lib/poolboy/version.rb
75
+ - poolboy.gemspec
76
+ homepage: http://www.samlambert.com
77
+ licenses:
78
+ - MIT
79
+ metadata: {}
80
+ post_install_message:
81
+ rdoc_options: []
82
+ require_paths:
83
+ - lib
84
+ required_ruby_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ! '>='
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ required_rubygems_version: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ requirements: []
95
+ rubyforge_project:
96
+ rubygems_version: 2.0.3
97
+ signing_key:
98
+ specification_version: 4
99
+ summary: Poolboy lets you view the data in your buffer pool
100
+ test_files: []