maatkit-ruby 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (40) hide show
  1. data/Changelog +0 -0
  2. data/MIT-LICENSE +21 -0
  3. data/README +26 -0
  4. data/lib/maatkit-ruby.rb +11 -0
  5. data/lib/maatkit-ruby/mk-archiver.rb +473 -0
  6. data/lib/maatkit-ruby/mk-checksum-filter.rb +122 -0
  7. data/lib/maatkit-ruby/mk-deadlock-logger.rb +223 -0
  8. data/lib/maatkit-ruby/mk-duplicate-key-checker.rb +239 -0
  9. data/lib/maatkit-ruby/mk-error-log.rb +240 -0
  10. data/lib/maatkit-ruby/mk-fifo-split.rb +130 -0
  11. data/lib/maatkit-ruby/mk-find.rb +137 -0
  12. data/lib/maatkit-ruby/mk-heartbeat.rb +300 -0
  13. data/lib/maatkit-ruby/mk-index-usage.rb +164 -0
  14. data/lib/maatkit-ruby/mk-kill.rb +124 -0
  15. data/lib/maatkit-ruby/mk-loadavg.rb +313 -0
  16. data/lib/maatkit-ruby/mk-log-player.rb +316 -0
  17. data/lib/maatkit-ruby/mk-merge-mqd-results.rb +248 -0
  18. data/lib/maatkit-ruby/mk-parallel-dump.rb +400 -0
  19. data/lib/maatkit-ruby/mk-parallel-restore.rb +133 -0
  20. data/lib/maatkit-ruby/mk-profile-compact.rb +87 -0
  21. data/lib/maatkit-ruby/mk-purge-logs.rb +99 -0
  22. data/lib/maatkit-ruby/mk-query-advisor.rb +105 -0
  23. data/lib/maatkit-ruby/mk-query-digest.rb +149 -0
  24. data/lib/maatkit-ruby/mk-query-profiler.rb +106 -0
  25. data/lib/maatkit-ruby/mk-show-grants.rb +103 -0
  26. data/lib/maatkit-ruby/mk-slave-delay.rb +102 -0
  27. data/lib/maatkit-ruby/mk-slave-find.rb +98 -0
  28. data/lib/maatkit-ruby/mk-slave-move.rb +99 -0
  29. data/lib/maatkit-ruby/mk-slave-prefetch.rb +124 -0
  30. data/lib/maatkit-ruby/mk-slave-restart.rb +116 -0
  31. data/lib/maatkit-ruby/mk-table-checksum.rb +151 -0
  32. data/lib/maatkit-ruby/mk-table-sync.rb +468 -0
  33. data/lib/maatkit-ruby/mk-upgrade.rb +118 -0
  34. data/lib/maatkit-ruby/mk-variable-advisor.rb +99 -0
  35. data/lib/maatkit-ruby/mk-visual-explain.rb +98 -0
  36. data/lib/maatkit-ruby/version.rb +17 -0
  37. data/setup.rb +1585 -0
  38. data/test/test_helper.rb +2 -0
  39. data/test/test_maatkit_ruby.rb +11 -0
  40. metadata +105 -0
@@ -0,0 +1,240 @@
1
+ # = maatkit-ruby - A maatkit gem for Ruby
2
+ #
3
+ # Homepage:: http://github.com/jjuliano/maatkit-ruby
4
+ # Author:: Joel Bryan Juliano
5
+ # Copyright:: (cc) 2011 Joel Bryan Juliano
6
+ # License:: MIT
7
+
8
+ #
9
+ # Find new and different MySQL error log entries.
10
+ #
11
+ # Maatkit::ErrorLog.new( array, str, array)
12
+ #
13
+ class Maatkit::ErrorLog
14
+
15
+ #
16
+ # Prompt for a password when connecting to MySQL.
17
+ attr_accessor :ask_pass # FALSE
18
+
19
+ #
20
+ # short form: -A; type: string
21
+ # Default character set. If the value is utf8, sets Perl's binmode on STDOUT to utf8, passes the
22
+ # mysql_enable_utf8 option to DBD::mysql, and runs SET NAMES UTF8 after connecting to MySQL. Any other
23
+ # value sets binmode on STDOUT without the utf8 layer, and runs SET NAMES after connecting to MySQL.
24
+ attr_accessor :charset # (No # value)
25
+
26
+ #
27
+ # type: Array
28
+ # Read this comma-separated list of config files; if specified, this must be the first option on the
29
+ # command line.
30
+ attr_accessor :config # /etc/maatkit/maatkit.conf,/etc/maatkit/mk_error_log.conf,/home/joel/.maatkit.conf,/home/joel/.mk_error_log.conf
31
+
32
+ #
33
+ # default: yes
34
+ # Continue parsing even if there is an error.
35
+ attr_accessor :continue_on_error # TRUE
36
+
37
+ #
38
+ # short form: -F; type: string
39
+ # Only read mysql options from the given file. You must give an absolute pathname.
40
+ attr_accessor :defaults_file # (No # value)
41
+
42
+ #
43
+ # Show help and exit.
44
+ attr_accessor :help # TRUE
45
+
46
+ #
47
+ # short form: -h; type: string
48
+ # Connect to host.
49
+ attr_accessor :host # (No # value)
50
+
51
+ #
52
+ # default: yes
53
+ # Load known, built-in patterns.
54
+ # mk-error-log has a built-in list of known patterns. This are normally loaded by default, but if you
55
+ # don't want them to be used you can disable them from being loaded by specifying "--no-known-patterns".
56
+ attr_accessor :known_patterns # TRUE
57
+
58
+ #
59
+ # type: string
60
+ # Load a list of known patterns from this file.
61
+ # Patterns in the file should be formatted like this:
62
+ # name1
63
+ # level1
64
+ # pattern1
65
+ # nameN
66
+ # levelN
67
+ # patternN
68
+ # Each pattern has three parts: name, level and regex pattern. Patterns are separated by a blank line.
69
+ # A pattern's name is what is printed under the Message column in the "OUTPUT". Likewise, its level is
70
+ # printed under the Level column. The regex pattern is what mk-error-log uses to match this pattern.
71
+ # Any Perl regular expression should be valid.
72
+ # Here is a simple example:
73
+ # InnoDB: The first specified data file did not exist!
74
+ # info
75
+ # InnoDB: The first specified data file \S+
76
+ # InnoDB: Rolling back of trx complete
77
+ # info
78
+ # InnoDB: Rolling back of trx id .*?complete
79
+ # See also "--save-patterns".
80
+ attr_accessor :load_patterns # (No # value)
81
+
82
+ #
83
+ # short form: -p; type: string
84
+ # Password to use when connecting.
85
+ attr_accessor :password # (No # value)
86
+
87
+ #
88
+ # type: string
89
+ # Create the given PID file when daemonized. The file contains the process ID of the daemonized
90
+ # instance. The PID file is removed when the daemonized instance exits. The program checks for the
91
+ # existence of the PID file when starting; if it exists and the process with the matching PID exists, the
92
+ # program exits.
93
+ attr_accessor :pid # (No # value)
94
+
95
+ #
96
+ # short form: -P; type: int
97
+ # Port number to use for connection.
98
+ attr_accessor :port # (No # value)
99
+
100
+ #
101
+ # type: string
102
+ # Read and write resume position to this file; resume parsing from last position.
103
+ # By default mk-error-log parses an error logs from start (pos 0) to finish. This option allows the tool
104
+ # to start parsing an error log from where it last ended as long as the file has the same name and inode
105
+ # (e.g. it hasn't been rotated) and its size is larger. If the log file's name or inode is different,
106
+ # then a new resume file is started and the old resume file is saved with the old error log's inode
107
+ # appended to its file name. If the log file's size is smaller (e.g. the log was truncated), then
108
+ # parsing begins from the start.
109
+ # A resume file is a simple, four line text file like:
110
+ # file:/path/to/err.log
111
+ # inode:12345
112
+ # pos:67890
113
+ # size:987100
114
+ # The resume file is read at startup and updated when mk-error-log finishes parsing the log. Note that
115
+ # CTRL-C prevents the resume file from being updated.
116
+ # If the resume file doesn't exist it is created.
117
+ # A line is printed before the main report which tells when and at what position parsing began for the
118
+ # error log if it was resumed.
119
+ attr_accessor :resume # (No # value)
120
+
121
+ #
122
+ # type: string
123
+ # After running save all new and old patterns to this file.
124
+ # This option causes mk-error-log to save every pattern it has to the file. This file can be used for
125
+ # subsequent runs with "--load-patterns". The patterns are saved in descending order of frequency, so
126
+ # the most frequent patterns are at top.
127
+ attr_accessor :save_patterns # (No # value)
128
+
129
+ #
130
+ # type: string; default: wait_timeout=10000
131
+ # Set these MySQL variables. Immediately after connecting to MySQL, this string will be appended to SET
132
+ # and executed.
133
+ attr_accessor :set_vars # wait_timeout=10000
134
+
135
+ #
136
+ # type: string
137
+ # Parse only events newer than this value (parse events since this date).
138
+ # This option allows you to ignore events older than a certain value and parse only those events which
139
+ # are more recent than the value. The value can be several types:
140
+ # * Simple time value N with optional suffix: N[shmd], where
141
+ # # s=seconds, h=hours, m=minutes, d=days (default s if no suffix
142
+ # # given); this is like saying "since N[shmd] ago"
143
+ # * Full date with optional hours:minutes:seconds: YYYY-MM-DD [HH:MM::SS]
144
+ # * Short, MySQL-style date: YYMMDD [HH:MM:SS]
145
+ # Events are assumed to be in chronological--older events at the beginning of the log and newer events at
146
+ # the end of the log. "--since" is strict: it ignores all events until one is found that is new enough.
147
+ # Therefore, if the events are not consistently timestamped, some may be ignored which are actually new
148
+ # enough.
149
+ # See also "--until".
150
+ attr_accessor :since # (No # value)
151
+
152
+ #
153
+ # short form: -S; type: string
154
+ # Socket file to use for connection.
155
+ attr_accessor :socket # (No # value)
156
+
157
+ #
158
+ # type: string
159
+ # Parse only events older than this value (parse events until this date).
160
+ # This option allows you to ignore events newer than a certain value and parse only those events which
161
+ # are older than the value. The value can be one of the same types listed for "--since".
162
+ # Unlike "--since", "--until" is not strict: all events are parsed until one has a timestamp that is
163
+ # equal to or greater than "--until". Then all subsequent events are ignored.
164
+ attr_accessor :until # (No # value)
165
+
166
+ #
167
+ # short form: -u; type: string
168
+ # User for login if not current user.
169
+ attr_accessor :user # (No # value)
170
+
171
+ #
172
+ # Show version and exit.
173
+ attr_accessor :version # FALSE
174
+
175
+ #
176
+ # Sets the executable path, otherwise the environment path will be used.
177
+ #
178
+ attr_accessor :path_to_mk_error_log
179
+
180
+ #
181
+ # Returns a new ErrorLog Object
182
+ #
183
+ def initialize()
184
+ end
185
+
186
+ #
187
+ # Execute the command
188
+ #
189
+ def start(options = nil)
190
+ tmp = Tempfile.new('tmp')
191
+ command = option_string() + options.to_s + " 2> " + tmp.path
192
+ success = system(command)
193
+ if success
194
+ begin
195
+ while (line = tmp.readline)
196
+ line.chomp
197
+ selected_string = line
198
+ end
199
+ rescue EOFError
200
+ tmp.close
201
+ end
202
+ return selected_string
203
+ else
204
+ tmp.close!
205
+ return success
206
+ end
207
+ end
208
+
209
+ def config
210
+ option_string()
211
+ end
212
+
213
+ private
214
+
215
+ def option_string()
216
+
217
+ unless @path_to_mk_error_log
218
+ ostring = "mk-error-log "
219
+ else
220
+ ostring = @path_to_mk_error_log + " "
221
+ end
222
+
223
+ self.instance_variables.each do |i|
224
+ tmp_value = self.instance_variable_get "#{i}"
225
+ tmp_string = i.gsub("_", "-").gsub("@", "--")
226
+ unless tmp_string == "--path-to-mk-error-log"
227
+ if (tmp_value.is_a? TrueClass) || (tmp_value.is_a? FalseClass)
228
+ ostring += "#{tmp_string} "
229
+ else
230
+ ostring += "#{tmp_string} #{tmp_value} "
231
+ end
232
+ end
233
+ end
234
+
235
+ return ostring
236
+
237
+ end
238
+
239
+ end
240
+
@@ -0,0 +1,130 @@
1
+ # = maatkit-ruby - A maatkit gem for Ruby
2
+ #
3
+ # Homepage:: http://github.com/jjuliano/maatkit-ruby
4
+ # Author:: Joel Bryan Juliano
5
+ # Copyright:: (cc) 2011 Joel Bryan Juliano
6
+ # License:: MIT
7
+
8
+ #
9
+ # Split files and pipe lines to a fifo without really splitting.
10
+ #
11
+ # Maatkit::FifoSplit.new( array, str, array)
12
+ #
13
+ class Maatkit::FifoSplit
14
+
15
+ #
16
+ # type: Array
17
+ # Read this comma-separated list of config files; if specified, this must be the first option on the
18
+ # command line.
19
+ attr_accessor :config # /etc/maatkit/maatkit.conf,/etc/maatkit/mk-fifo-split.conf,/home/joel/.maatkit.conf,/home/joel/.mk-fifo-split.conf
20
+
21
+ #
22
+ # type: string; default: /tmp/mk-fifo-split
23
+ # The name of the fifo from which the lines can be read.
24
+ attr_accessor :fifo # /tmp/mk-fifo-split
25
+
26
+ #
27
+ # Remove the fifo if it exists already, then create it again.
28
+ attr_accessor :force # FALSE
29
+
30
+ #
31
+ # Show help and exit.
32
+ attr_accessor :help # TRUE
33
+
34
+ #
35
+ # type: int; default: 1000
36
+ # The number of lines to read in each chunk.
37
+ attr_accessor :lines # 1000
38
+
39
+ #
40
+ # type: int; default: 0
41
+ # Begin at the Nth line. If the argument is 0, all lines are printed to the fifo. If 1, then beginning
42
+ # at the first line, lines are printed (exactly the same as 0). If 2, the first line is skipped, and the
43
+ # 2nd and subsequent lines are printed to the fifo.
44
+ attr_accessor :offset # (No # value)
45
+
46
+ #
47
+ # type: string
48
+ # Create the given PID file. The file contains the process ID of the script. The PID file is removed
49
+ # when the script exits. Before starting, the script checks if the PID file already exists. If it does
50
+ # not, then the script creates and writes its own PID to it. If it does, then the script checks the
51
+ # following: if the file contains a PID and a process is running with that PID, then the script dies; or,
52
+ # if there is no process running with that PID, then the script overwrites the file with its own PID and
53
+ # starts; else, if the file contains no PID, then the script dies.
54
+ attr_accessor :pid # (No # value)
55
+
56
+ #
57
+ # Print out statistics between chunks. The statistics are the number of chunks, the number of lines,
58
+ # elapsed time, and lines per second overall and during the last chunk.
59
+ attr_accessor :statistics # FALSE
60
+
61
+ #
62
+ # Show version and exit.
63
+ attr_accessor :version # FALSE
64
+
65
+ #
66
+ # Sets the executable path, otherwise the environment path will be used.
67
+ #
68
+ attr_accessor :path_to_mk_fifo_split
69
+
70
+ #
71
+ # Returns a new FifoSplit Object
72
+ #
73
+ def initialize()
74
+ end
75
+
76
+ #
77
+ # Execute the command
78
+ #
79
+ def start(options = nil)
80
+ tmp = Tempfile.new('tmp')
81
+ command = option_string() + options.to_s + " 2> " + tmp.path
82
+ success = system(command)
83
+ if success
84
+ begin
85
+ while (line = tmp.readline)
86
+ line.chomp
87
+ selected_string = line
88
+ end
89
+ rescue EOFError
90
+ tmp.close
91
+ end
92
+ return selected_string
93
+ else
94
+ tmp.close!
95
+ return success
96
+ end
97
+ end
98
+
99
+ def config
100
+ option_string()
101
+ end
102
+
103
+ private
104
+
105
+ def option_string()
106
+
107
+ unless @path_to_mk_fifo_split
108
+ ostring = "mk-fifo-split "
109
+ else
110
+ ostring = @path_to_mk_fifo_split + " "
111
+ end
112
+
113
+ self.instance_variables.each do |i|
114
+ tmp_value = self.instance_variable_get "#{i}"
115
+ tmp_string = i.gsub("_", "-").gsub("@", "--")
116
+ unless tmp_string == "--path-to-mk-fifo-split"
117
+ if (tmp_value.is_a? TrueClass) || (tmp_value.is_a? FalseClass)
118
+ ostring += "#{tmp_string} "
119
+ else
120
+ ostring += "#{tmp_string} #{tmp_value} "
121
+ end
122
+ end
123
+ end
124
+
125
+ return ostring
126
+
127
+ end
128
+
129
+ end
130
+
@@ -0,0 +1,137 @@
1
+ # = maatkit-ruby - A maatkit gem for Ruby
2
+ #
3
+ # Homepage:: http://github.com/jjuliano/maatkit-ruby
4
+ # Author:: Joel Bryan Juliano
5
+ # Copyright:: (cc) 2011 Joel Bryan Juliano
6
+ # License:: MIT
7
+
8
+ #
9
+ # Find MySQL tables and execute actions, like GNU find.
10
+ #
11
+ # Maatkit::Find.new( array, str, array)
12
+ #
13
+ class Maatkit::Find
14
+
15
+ attr_accessor :ask_pass # FALSE
16
+ attr_accessor :autoinc # (No value)
17
+ attr_accessor :avgrowlen # (No value)
18
+ attr_accessor :case_insensitive # FALSE
19
+ attr_accessor :charset # (No value)
20
+ attr_accessor :checksum # (No value)
21
+ attr_accessor :cmin # (No value)
22
+ attr_accessor :collation # (No value)
23
+ attr_accessor :column_name # (No value)
24
+ attr_accessor :column_type # (No value)
25
+ attr_accessor :comment # (No value)
26
+ attr_accessor :config # /etc/maatkit/maatkit.conf,/etc/maatkit/mk_find.conf,/home/joel/.maatkit.conf,/home/joel/.mk_find.conf
27
+ attr_accessor :connection_id # (No value)
28
+ attr_accessor :createopts # (No value)
29
+ attr_accessor :ctime # (No value)
30
+ attr_accessor :datafree # (No value)
31
+ attr_accessor :datasize # (No value)
32
+ attr_accessor :day_start # FALSE
33
+ attr_accessor :dblike # (No value)
34
+ attr_accessor :dbregex # (No value)
35
+ attr_accessor :defaults_file # (No value)
36
+ attr_accessor :empty # FALSE
37
+ attr_accessor :engine # (No value)
38
+ attr_accessor :exec # (No value)
39
+ attr_accessor :exec_dsn # (No value)
40
+ attr_accessor :exec_plus # (No value)
41
+ attr_accessor :function # (No value)
42
+ attr_accessor :help # TRUE
43
+ attr_accessor :host # (No value)
44
+ attr_accessor :indexsize # (No value)
45
+ attr_accessor :kmin # (No value)
46
+ attr_accessor :ktime # (No value)
47
+ attr_accessor :mmin # (No value)
48
+ attr_accessor :mtime # (No value)
49
+ attr_accessor :or # FALSE
50
+ attr_accessor :password # (No value)
51
+ attr_accessor :pid # (No value)
52
+ attr_accessor :port # (No value)
53
+ attr_accessor :print # FALSE
54
+ attr_accessor :printf # (No value)
55
+ attr_accessor :procedure # (No value)
56
+ attr_accessor :quote # TRUE
57
+ attr_accessor :rowformat # (No value)
58
+ attr_accessor :rows # (No value)
59
+ attr_accessor :server_id # (No value)
60
+ attr_accessor :set_vars # wait_timeout=10000
61
+ attr_accessor :socket # (No value)
62
+ attr_accessor :tablesize # (No value)
63
+ attr_accessor :tbllike # (No value)
64
+ attr_accessor :tblregex # (No value)
65
+ attr_accessor :tblversion # (No value)
66
+ attr_accessor :trigger # (No value)
67
+ attr_accessor :trigger_table # (No value)
68
+ attr_accessor :user # (No value)
69
+ attr_accessor :version # FALSE
70
+ attr_accessor :view # (No value)
71
+
72
+ #
73
+ # Sets the executable path, otherwise the environment path will be used.
74
+ #
75
+ attr_accessor :path_to_mk_find
76
+
77
+ #
78
+ # Returns a new Find Object
79
+ #
80
+ def initialize()
81
+ end
82
+
83
+ #
84
+ # Execute the command
85
+ #
86
+ def start(options = nil)
87
+ tmp = Tempfile.new('tmp')
88
+ command = option_string() + options.to_s + " 2> " + tmp.path
89
+ success = system(command)
90
+ if success
91
+ begin
92
+ while (line = tmp.readline)
93
+ line.chomp
94
+ selected_string = line
95
+ end
96
+ rescue EOFError
97
+ tmp.close
98
+ end
99
+ return selected_string
100
+ else
101
+ tmp.close!
102
+ return success
103
+ end
104
+ end
105
+
106
+ def config
107
+ option_string()
108
+ end
109
+
110
+ private
111
+
112
+ def option_string()
113
+
114
+ unless @path_to_mk_find
115
+ ostring = "mk-find "
116
+ else
117
+ ostring = @path_to_mk_find + " "
118
+ end
119
+
120
+ self.instance_variables.each do |i|
121
+ tmp_value = self.instance_variable_get "#{i}"
122
+ tmp_string = i.gsub("_", "-").gsub("@", "--")
123
+ unless tmp_string == "--path-to-mk-find"
124
+ if (tmp_value.is_a? TrueClass) || (tmp_value.is_a? FalseClass)
125
+ ostring += "#{tmp_string} "
126
+ else
127
+ ostring += "#{tmp_string} #{tmp_value} "
128
+ end
129
+ end
130
+ end
131
+
132
+ return ostring
133
+
134
+ end
135
+
136
+ end
137
+