dbtop 0.0.0
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.
- data/.bnsignore +18 -0
- data/Gemfile +2 -0
- data/Gemfile.lock +10 -0
- data/History.txt +4 -0
- data/README.md +104 -0
- data/Rakefile +17 -0
- data/bin/dbtop +157 -0
- data/lib/dbtop.rb +60 -0
- data/spec/dbtop_spec.rb +6 -0
- data/spec/spec_helper.rb +17 -0
- data/test/test_dbtop.rb +0 -0
- data/version.txt +1 -0
- metadata +76 -0
data/.bnsignore
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
# The list of files that should be ignored by Mr Bones.
|
2
|
+
# Lines that start with '#' are comments.
|
3
|
+
#
|
4
|
+
# A .gitignore file can be used instead by setting it as the ignore
|
5
|
+
# file in your Rakefile:
|
6
|
+
#
|
7
|
+
# Bones {
|
8
|
+
# ignore_file '.gitignore'
|
9
|
+
# }
|
10
|
+
#
|
11
|
+
# For a project with a C extension, the following would be a good set of
|
12
|
+
# exclude patterns (uncomment them if you want to use them):
|
13
|
+
# *.[oa]
|
14
|
+
# *~
|
15
|
+
announcement.txt
|
16
|
+
coverage
|
17
|
+
doc
|
18
|
+
pkg
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
data/History.txt
ADDED
data/README.md
ADDED
@@ -0,0 +1,104 @@
|
|
1
|
+
dbtop
|
2
|
+
===========
|
3
|
+
|
4
|
+
Similar to the Unix 'top' tool, this Ruby gem will provide process
|
5
|
+
monitoring for your MySQL database instance.
|
6
|
+
|
7
|
+
By using command line arguments or environmental variables, dbtop will
|
8
|
+
connect to your db and return your current process list (minus Sleep
|
9
|
+
processes) on screen, in a terminal Curses buffer.
|
10
|
+
|
11
|
+
By default, the port used will be 3306 unless the environment
|
12
|
+
variable for MYSQL_PORT is specified.
|
13
|
+
|
14
|
+
Features
|
15
|
+
--------
|
16
|
+
|
17
|
+
Easy out-of-the-box connectivity to your database if you use
|
18
|
+
environmental variables.
|
19
|
+
|
20
|
+
Won't make a mess of your terminal (drawn to a Curses buffer).
|
21
|
+
|
22
|
+
Examples
|
23
|
+
--------
|
24
|
+
|
25
|
+
If you don't have environmental variables set for your MySQL database,
|
26
|
+
run dbtop with command line arguments:
|
27
|
+
|
28
|
+
```bash
|
29
|
+
ruby dbtop.rb -u #{user} -p #{pass} -h #{host} -d #{database} -i 1
|
30
|
+
```
|
31
|
+
|
32
|
+
If you have environmental variables set for your MySQL database already,
|
33
|
+
just run dbtop :)
|
34
|
+
|
35
|
+
```bash
|
36
|
+
ruby dbtop.rb
|
37
|
+
```
|
38
|
+
|
39
|
+
```bash
|
40
|
+
ruby dbtop.rb -i 1
|
41
|
+
```
|
42
|
+
|
43
|
+
Note: You can quit the application by pressing 'q'
|
44
|
+
|
45
|
+
Requirements
|
46
|
+
------------
|
47
|
+
|
48
|
+
Ruby 1.9.2+
|
49
|
+
|
50
|
+
If you're using ENV variables:
|
51
|
+
|
52
|
+
MYSQL_USER
|
53
|
+
MYSQL_PASSWORD
|
54
|
+
MYSQL_HOST
|
55
|
+
MYSQL_DATABASE
|
56
|
+
MYSQL_PORT
|
57
|
+
|
58
|
+
Install
|
59
|
+
-------
|
60
|
+
|
61
|
+
Install all required gems by running:
|
62
|
+
|
63
|
+
```bash
|
64
|
+
bundle install
|
65
|
+
```
|
66
|
+
|
67
|
+
Install the gem manually by running:
|
68
|
+
|
69
|
+
```bash
|
70
|
+
rake gem:install
|
71
|
+
```
|
72
|
+
|
73
|
+
in the application folder.
|
74
|
+
|
75
|
+
Author
|
76
|
+
------
|
77
|
+
|
78
|
+
Original author: Alfred Moreno
|
79
|
+
|
80
|
+
License
|
81
|
+
-------
|
82
|
+
|
83
|
+
(The MIT License)
|
84
|
+
|
85
|
+
Copyright (c) 2012 Alfred Moreno
|
86
|
+
|
87
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
88
|
+
a copy of this software and associated documentation files (the
|
89
|
+
'Software'), to deal in the Software without restriction, including
|
90
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
91
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
92
|
+
permit persons to whom the Software is furnished to do so, subject to
|
93
|
+
the following conditions:
|
94
|
+
|
95
|
+
The above copyright notice and this permission notice shall be
|
96
|
+
included in all copies or substantial portions of the Software.
|
97
|
+
|
98
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
99
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
100
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
101
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
102
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
103
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
104
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
|
2
|
+
begin
|
3
|
+
require 'bones'
|
4
|
+
rescue LoadError
|
5
|
+
abort '### Please install the "bones" gem ###'
|
6
|
+
end
|
7
|
+
|
8
|
+
task :default => 'test:run'
|
9
|
+
task 'gem:release' => 'test:run'
|
10
|
+
|
11
|
+
Bones {
|
12
|
+
name 'dbtop'
|
13
|
+
authors 'Alfred Moreno'
|
14
|
+
email 'kryptek@kryptek.org'
|
15
|
+
url 'http://github.com/kryptek'
|
16
|
+
}
|
17
|
+
|
data/bin/dbtop
ADDED
@@ -0,0 +1,157 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# ::::::::: :::::::::: ::: ::: :::::::: ::::::::: ::::::::
|
3
|
+
# :+: :+: :+: :+: :+: :+: :+: :+: :+: :+: :+:
|
4
|
+
# +:+ +:+ +:+ +:+ +:+ +:+ +:+ +:+ +:+ +:+
|
5
|
+
# +#+ +:+ +#++:++# +#+ +:+ +#+ +:+ +#++:++#+ +#++:++#++
|
6
|
+
# +#+ +#+ +#+ +#+ +#+ +#+ +#+ +#+ +#+
|
7
|
+
# #+# #+# #+# #+#+#+# #+# #+# #+# #+# #+#
|
8
|
+
# ######### ########## ### ######## ### ########
|
9
|
+
#
|
10
|
+
# @ Zumba Fitness, LLC
|
11
|
+
# ------------------------------------------------------------------------------
|
12
|
+
# filename: dbtop.rb
|
13
|
+
# author: alfred.moreno@zumba.com
|
14
|
+
# purpose: Process monitor for MySQL Databases; ignores 'Sleep' processes.
|
15
|
+
# ------------------------------------------------------------------------------
|
16
|
+
require 'curses'
|
17
|
+
require 'terminal-table'
|
18
|
+
require 'optparse'
|
19
|
+
include Curses
|
20
|
+
|
21
|
+
class MysqlTop
|
22
|
+
|
23
|
+
#############################################################################
|
24
|
+
# Public: Initialize the MysqlTop class and screen buffer
|
25
|
+
#
|
26
|
+
# Returns: nothing
|
27
|
+
#############################################################################
|
28
|
+
def initialize(options)
|
29
|
+
|
30
|
+
@user = options[:user] || ENV['MYSQL_USER']
|
31
|
+
@pass = options[:pass] || ENV['MYSQL_PASSWORD']
|
32
|
+
@host = options[:host] || ENV['MYSQL_HOST']
|
33
|
+
@db = options[:db] || ENV['MYSQL_DATABASE']
|
34
|
+
@port = 3306 || ENV['MYSQL_PORT']
|
35
|
+
@interval = options[:interval] || 5
|
36
|
+
validate
|
37
|
+
|
38
|
+
tbl = Terminal::Table.new headings: [
|
39
|
+
'Time',
|
40
|
+
'User',
|
41
|
+
'Host',
|
42
|
+
'DB',
|
43
|
+
'State',
|
44
|
+
'Cmd'
|
45
|
+
]
|
46
|
+
|
47
|
+
begin
|
48
|
+
Curses.timeout=0
|
49
|
+
loop do
|
50
|
+
|
51
|
+
case getch
|
52
|
+
when 'q'
|
53
|
+
exit
|
54
|
+
end
|
55
|
+
|
56
|
+
%x[mysql -A -u #@user -p#@pass -h #@host #@db -e "show processlist"].lines.each do |line|
|
57
|
+
next if line.include?('Sleep')
|
58
|
+
|
59
|
+
line = line.split(' ')
|
60
|
+
|
61
|
+
row = {
|
62
|
+
id: line[0],
|
63
|
+
user: line[1],
|
64
|
+
host: line[2],
|
65
|
+
db: line[3],
|
66
|
+
cmd: line[4],
|
67
|
+
time: line[5],
|
68
|
+
state: line[6],
|
69
|
+
info: line[7]
|
70
|
+
}
|
71
|
+
tbl << [line[5], line[1], line[2], line[3], line[6], line[4]]
|
72
|
+
end
|
73
|
+
|
74
|
+
write(0,0,tbl.to_s)
|
75
|
+
tbl.rows = tbl.rows.clear
|
76
|
+
sleep @interval
|
77
|
+
|
78
|
+
end
|
79
|
+
ensure
|
80
|
+
close_screen
|
81
|
+
end
|
82
|
+
|
83
|
+
end
|
84
|
+
|
85
|
+
#############################################################################
|
86
|
+
# Public: Validates that credentials for connecting to the DB are complete
|
87
|
+
#
|
88
|
+
# Returns: nothing
|
89
|
+
#############################################################################
|
90
|
+
def validate
|
91
|
+
[@user,@pass,@host,@db].each { |param|
|
92
|
+
raise "Insufficient parameters to connect to MySQL Database!" if param.nil?
|
93
|
+
}
|
94
|
+
end
|
95
|
+
|
96
|
+
#############################################################################
|
97
|
+
# Public: Initializes the screen buffer with specified options.
|
98
|
+
#
|
99
|
+
# Returns: nothing
|
100
|
+
#############################################################################
|
101
|
+
def init_screen
|
102
|
+
nl
|
103
|
+
Curses.noecho # Don't echo characters to the screen.
|
104
|
+
crmode
|
105
|
+
Curses.init_screen # Initialize the screen buffer.
|
106
|
+
Curses.start_color
|
107
|
+
#Curses.color_set(COLOR_GREEN)
|
108
|
+
Curses.stdscr.keypad(true) # Enable arrow keys.
|
109
|
+
Curses.doupdate
|
110
|
+
curs_set(0,0)
|
111
|
+
begin
|
112
|
+
yield
|
113
|
+
ensure
|
114
|
+
Curses.close_screen
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
#############################################################################
|
119
|
+
# Public: Writes text at a specific set of coordinates on your screen
|
120
|
+
#
|
121
|
+
# Returns: nothing
|
122
|
+
#############################################################################
|
123
|
+
def write(x,y,text)
|
124
|
+
Curses.setpos(x,y)
|
125
|
+
Curses.addstr(text)
|
126
|
+
for x in 1..Curses.lines
|
127
|
+
Curses.deleteln
|
128
|
+
end
|
129
|
+
Curses.setpos(text.lines.count-1,0)
|
130
|
+
Curses.addstr(text.lines.take(3)[2])
|
131
|
+
Curses.refresh
|
132
|
+
end
|
133
|
+
|
134
|
+
end
|
135
|
+
|
136
|
+
options = {}
|
137
|
+
opts = OptionParser.new do |opts|
|
138
|
+
opts.on('-u U', String, 'Database username') do |user|
|
139
|
+
options[:user] = user
|
140
|
+
end
|
141
|
+
opts.on('-p P', String, 'Database password') do |password|
|
142
|
+
options[:pass] = password
|
143
|
+
end
|
144
|
+
opts.on('-h H', String, 'Database hostname') do |hostname|
|
145
|
+
options[:host] = hostname
|
146
|
+
end
|
147
|
+
opts.on('-d D', String, 'Database to use') do |database|
|
148
|
+
options[:db] = database
|
149
|
+
end
|
150
|
+
opts.on('-i I', Integer, 'Integer for refresh') do |interval|
|
151
|
+
options[:interval] = interval
|
152
|
+
end
|
153
|
+
end
|
154
|
+
opts.parse!(ARGV)
|
155
|
+
|
156
|
+
mysqltop = MysqlTop.new(options)
|
157
|
+
|
data/lib/dbtop.rb
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
|
2
|
+
module Dbtop
|
3
|
+
|
4
|
+
# :stopdoc:
|
5
|
+
LIBPATH = ::File.expand_path('..', __FILE__) + ::File::SEPARATOR
|
6
|
+
PATH = ::File.dirname(LIBPATH) + ::File::SEPARATOR
|
7
|
+
VERSION = ::File.read(PATH + 'version.txt').strip
|
8
|
+
# :startdoc:
|
9
|
+
|
10
|
+
# Returns the library path for the module. If any arguments are given,
|
11
|
+
# they will be joined to the end of the libray path using
|
12
|
+
# <tt>File.join</tt>.
|
13
|
+
#
|
14
|
+
def self.libpath( *args )
|
15
|
+
rv = args.empty? ? LIBPATH : ::File.join(LIBPATH, args.flatten)
|
16
|
+
if block_given?
|
17
|
+
begin
|
18
|
+
$LOAD_PATH.unshift LIBPATH
|
19
|
+
rv = yield
|
20
|
+
ensure
|
21
|
+
$LOAD_PATH.shift
|
22
|
+
end
|
23
|
+
end
|
24
|
+
return rv
|
25
|
+
end
|
26
|
+
|
27
|
+
# Returns the lpath for the module. If any arguments are given,
|
28
|
+
# they will be joined to the end of the path using
|
29
|
+
# <tt>File.join</tt>.
|
30
|
+
#
|
31
|
+
def self.path( *args )
|
32
|
+
rv = args.empty? ? PATH : ::File.join(PATH, args.flatten)
|
33
|
+
if block_given?
|
34
|
+
begin
|
35
|
+
$LOAD_PATH.unshift PATH
|
36
|
+
rv = yield
|
37
|
+
ensure
|
38
|
+
$LOAD_PATH.shift
|
39
|
+
end
|
40
|
+
end
|
41
|
+
return rv
|
42
|
+
end
|
43
|
+
|
44
|
+
# Utility method used to require all files ending in .rb that lie in the
|
45
|
+
# directory below this file that has the same name as the filename passed
|
46
|
+
# in. Optionally, a specific _directory_ name can be passed in such that
|
47
|
+
# the _filename_ does not have to be equivalent to the directory.
|
48
|
+
#
|
49
|
+
def self.require_all_libs_relative_to( fname, dir = nil )
|
50
|
+
dir ||= ::File.basename(fname, '.*')
|
51
|
+
search_me = ::File.expand_path(
|
52
|
+
::File.join(::File.dirname(fname), dir, '**', '*.rb'))
|
53
|
+
|
54
|
+
Dir.glob(search_me).sort.each {|rb| require rb}
|
55
|
+
end
|
56
|
+
|
57
|
+
end # module Dbtop
|
58
|
+
|
59
|
+
Dbtop.require_all_libs_relative_to(__FILE__)
|
60
|
+
|
data/spec/dbtop_spec.rb
ADDED
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
|
2
|
+
require 'rubygems'
|
3
|
+
require 'rspec'
|
4
|
+
|
5
|
+
require File.expand_path('../../lib/dbtop', __FILE__)
|
6
|
+
|
7
|
+
RSpec.configure do |config|
|
8
|
+
# == Mock Framework
|
9
|
+
#
|
10
|
+
# RSpec uses it's own mocking framework by default. If you prefer to
|
11
|
+
# use mocha, flexmock or RR, uncomment the appropriate line:
|
12
|
+
#
|
13
|
+
# config.mock_framework = :mocha
|
14
|
+
# config.mock_framework = :flexmock
|
15
|
+
# config.mock_framework = :rr
|
16
|
+
end
|
17
|
+
|
data/test/test_dbtop.rb
ADDED
File without changes
|
data/version.txt
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.0
|
metadata
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: dbtop
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Alfred Moreno
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-05-24 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: bones
|
16
|
+
requirement: &70169320893340 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 3.8.0
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *70169320893340
|
25
|
+
description: ! 'Similar to the Unix ''top'' tool, this Ruby gem will provide process
|
26
|
+
|
27
|
+
monitoring for your MySQL database instance.'
|
28
|
+
email: kryptek@kryptek.org
|
29
|
+
executables:
|
30
|
+
- dbtop
|
31
|
+
extensions: []
|
32
|
+
extra_rdoc_files:
|
33
|
+
- History.txt
|
34
|
+
- bin/dbtop
|
35
|
+
files:
|
36
|
+
- .bnsignore
|
37
|
+
- Gemfile
|
38
|
+
- Gemfile.lock
|
39
|
+
- History.txt
|
40
|
+
- README.md
|
41
|
+
- Rakefile
|
42
|
+
- bin/dbtop
|
43
|
+
- lib/dbtop.rb
|
44
|
+
- spec/dbtop_spec.rb
|
45
|
+
- spec/spec_helper.rb
|
46
|
+
- test/test_dbtop.rb
|
47
|
+
- version.txt
|
48
|
+
homepage: http://github.com/kryptek
|
49
|
+
licenses: []
|
50
|
+
post_install_message:
|
51
|
+
rdoc_options:
|
52
|
+
- --main
|
53
|
+
- README.md
|
54
|
+
require_paths:
|
55
|
+
- lib
|
56
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
63
|
+
none: false
|
64
|
+
requirements:
|
65
|
+
- - ! '>='
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '0'
|
68
|
+
requirements: []
|
69
|
+
rubyforge_project: dbtop
|
70
|
+
rubygems_version: 1.8.6
|
71
|
+
signing_key:
|
72
|
+
specification_version: 3
|
73
|
+
summary: Similar to the Unix 'top' tool, this Ruby gem will provide process monitoring
|
74
|
+
for your MySQL database instance.
|
75
|
+
test_files:
|
76
|
+
- test/test_dbtop.rb
|