maatkit-ruby 0.1.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.
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,300 @@
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
+ # Monitor MySQL replication delay.
10
+ #
11
+ # Maatkit::Heartbeat.new( array, str, array)
12
+ #
13
+ class Maatkit::Heartbeat
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
+ # Check slave delay once and exit.
28
+ attr_accessor :check # FALSE
29
+
30
+ #
31
+ # type: Array
32
+ # Read this comma-separated list of config files; if specified, this must be the first option on the
33
+ # command line.
34
+ attr_accessor :config # /etc/maatkit/maatkit.conf,/etc/maatkit/mk_heartbeat.conf,/home/joel/.maatkit.conf,/home/joel/.mk_heartbeat.conf
35
+
36
+ #
37
+ # Create the heartbeat "--table" if it does not exist.
38
+ # This option causes the table specified by "--database" and "--table" to be created with the following
39
+ # MAGIC_create_heartbeat table definition:
40
+ # CREATE TABLE heartbeat (
41
+ # # id int NOT NULL PRIMARY KEY,
42
+ # # ts datetime NOT NULL
43
+ # );
44
+ # The heartbeat table requires at least one row. If you manually create the heartbeat table, then you
45
+ # must insert a row by doing:
46
+ # INSERT INTO heartbeat (id) VALUES (1);
47
+ # This is done automatically by --create-table.
48
+ attr_accessor :create_table # FALSE
49
+
50
+ #
51
+ # Fork to the background and detach from the shell. POSIX operating systems only.
52
+ attr_accessor :daemonize # FALSE
53
+
54
+ #
55
+ # short form: -D; type: string
56
+ # The database to use for the connection.
57
+ attr_accessor :database # (No value)
58
+
59
+ #
60
+ # default: mysql; type: string
61
+ # Specify a driver for the connection; "mysql" and "Pg" are supported.
62
+ attr_accessor :dbi_driver # mysql
63
+
64
+ #
65
+ # short form: -F; type: string
66
+ # Only read mysql options from the given file. You must give an absolute pathname.
67
+ attr_accessor :defaults_file # (No value)
68
+
69
+ #
70
+ # type: string
71
+ # Print latest "--monitor" output to this file.
72
+ # When "--monitor" is given, prints output to the specified file instead of to STDOUT. The file is
73
+ # opened, truncated, and closed every interval, so it will only contain the most recent statistics.
74
+ # Useful when "--daemonize" is given.
75
+ attr_accessor :file # (No value)
76
+
77
+ #
78
+ # type: string; default: 1m,5m,15m
79
+ # Timeframes for averages.
80
+ # Specifies the timeframes over which to calculate moving averages when "--monitor" is given. Specify as
81
+ # a comma-separated list of numbers with suffixes. The suffix can be s for seconds, m for minutes, h for
82
+ # hours, or d for days. The size of the largest frame determines the maximum memory usage, as up to the
83
+ # specified number of per-second samples are kept in memory to calculate the averages. You can specify
84
+ # as many timeframes as you like.
85
+ attr_accessor :frames # 1m,5m,15m
86
+
87
+ #
88
+ # Show help and exit.
89
+ attr_accessor :help # TRUE
90
+
91
+ #
92
+ # short form: -h; type: string
93
+ # Connect to host.
94
+ attr_accessor :host # (No value)
95
+
96
+ #
97
+ # type: time; default: 1s
98
+ # Interval between updates and checks.
99
+ # How often to check or update values. The updates and checks will happen when the Unix time (seconds
100
+ # since epoch) is an even multiple of this value. The suffix is similar to "--frames".
101
+ attr_accessor :interval # 1
102
+
103
+ #
104
+ # type: string
105
+ # Print all output to this file when daemonized.
106
+ attr_accessor :log # (No value)
107
+
108
+ #
109
+ # Monitor slave delay continuously.
110
+ # Specifies that mk-heartbeat should check the slave's delay every second and report to STDOUT (or if
111
+ # "--file" is given, to the file instead). The output is the current delay followed by moving averages
112
+ # over the timeframe given in "--frames". For example,
113
+ # 5s [ 0.25s, 0.05s, 0.02s ]
114
+ attr_accessor :monitor # FALSE
115
+
116
+ #
117
+ # short form: -p; type: string
118
+ # Password to use when connecting.
119
+ attr_accessor :password # (No value)
120
+
121
+ #
122
+ # type: string
123
+ # Create the given PID file when daemonized. The file contains the process ID of the daemonized
124
+ # instance. The PID file is removed when the daemonized instance exits. The program checks for the
125
+ # existence of the PID file when starting; if it exists and the process with the matching PID exists, the
126
+ # program exits.
127
+ attr_accessor :pid # (No value)
128
+
129
+ #
130
+ # short form: -P; type: int
131
+ # Port number to use for connection.
132
+ attr_accessor :port # (No value)
133
+
134
+ #
135
+ # short form: -q
136
+ # Suppresses normal output.
137
+ attr_accessor :quiet # FALSE
138
+
139
+ #
140
+ # type: int
141
+ # Check slaves recursively to this depth in "--check" mode.
142
+ # Try to discover slave servers recursively, to the specified depth. After discovering servers, run the
143
+ # check on each one of them and print the hostname (if possible), followed by the slave delay.
144
+ # This currently works only with MySQL. See "--recursion-method".
145
+ attr_accessor :recurse # (No value)
146
+
147
+ #
148
+ # type: string
149
+ # Preferred recursion method used to find slaves.
150
+ # Possible methods are:
151
+ # METHOD # # USES
152
+ # =========== ================
153
+ # processlist SHOW PROCESSLIST
154
+ # hosts # # SHOW SLAVE HOSTS
155
+ # The processlist method is preferred because SHOW SLAVE HOSTS is not reliable. However, the hosts
156
+ # method is required if the server uses a non-standard port (not 3306). Usually mk-heartbeat does the
157
+ # right thing and finds the slaves, but you may give a preferred method and it will be used first. If it
158
+ # doesn't find any slaves, the other methods will be tried.
159
+ attr_accessor :recursion_method # (No value)
160
+
161
+ #
162
+ # Use "REPLACE" instead of "UPDATE" for --update.
163
+ # When running in "--update" mode, use "REPLACE" instead of "UPDATE" to set the heartbeat table's
164
+ # timestamp. The "REPLACE" statement is a MySQL extension to SQL. This option is useful when you don't
165
+ # know whether the table contains any rows or not.
166
+ attr_accessor :replace # FALSE
167
+
168
+ #
169
+ # type: time
170
+ # Time to run before exiting.
171
+ attr_accessor :run_time # (No value)
172
+
173
+ #
174
+ # type: string; default: /tmp/mk-heartbeat-sentinel
175
+ # Exit if this file exists.
176
+ attr_accessor :sentinel # /tmp/mk_heartbeat_sentinel
177
+
178
+ #
179
+ # type: string; default: wait_timeout=10000
180
+ # Set these MySQL variables. Immediately after connecting to MySQL, this string will be appended to SET
181
+ # and executed.
182
+ attr_accessor :set_vars # wait_timeout=10000
183
+
184
+ #
185
+ # type: int; default: 500000
186
+ # How long to delay checks, in milliseconds.
187
+ # The default is to delay checks one half second. Since the update happens as soon as possible after the
188
+ # beginning of the second on the master, this allows one half second of replication delay before
189
+ # reporting that the slave lags the master by one second. If your clocks are not completely accurate or
190
+ # there is some other reason you'd like to delay the slave more or less, you can tweak this value. Try
191
+ # setting the "MKDEBUG" environment variable to see the effect this has.
192
+ attr_accessor :skew # 500000
193
+
194
+ #
195
+ # short form: -S; type: string
196
+ # Socket file to use for connection.
197
+ attr_accessor :socket # (No value)
198
+
199
+ #
200
+ # Stop running instances by creating the sentinel file.
201
+ # This should have the effect of stopping all running instances which are watching the same sentinel
202
+ # file. If none of "--update", "--monitor" or "--check" is specified, "mk-heartbeat" will exit after
203
+ # creating the file. If one of these is specified, "mk-heartbeat" will wait the interval given by
204
+ # "--interval", then remove the file and continue working.
205
+ # You might find this handy to stop cron jobs gracefully if necessary, or to replace one running instance
206
+ # with another. For example, if you want to stop and restart "mk-heartbeat" every hour (just to make
207
+ # sure that it is restarted every hour, in case of a server crash or some other problem), you could use a
208
+ # "crontab" line like this:
209
+ # 0 * * * * mk-heartbeat --update -D test --stop \
210
+ # # --sentinel /tmp/mk-heartbeat-hourly
211
+ # The non-default "--sentinel" will make sure the hourly "cron" job stops only instances previously
212
+ # started with the same options (that is, from the same "cron" job).
213
+ # See also "--sentinel".
214
+ attr_accessor :stop # FALSE
215
+
216
+ #
217
+ # type: string; default: heartbeat
218
+ # The table to use for the heartbeat.
219
+ # Don't specify database.table; use "--database" to specify the database.
220
+ attr_accessor :table # heartbeat
221
+
222
+ #
223
+ # Update a master's heartbeat.
224
+ attr_accessor :update # FALSE
225
+
226
+ #
227
+ # short form: -u; type: string
228
+ # User for login if not current user.
229
+ attr_accessor :user # (No value)
230
+
231
+ #
232
+ # Show version and exit.
233
+ attr_accessor :version # FALSE
234
+
235
+ #
236
+ # Sets the executable path, otherwise the environment path will be used.
237
+ #
238
+ attr_accessor :path_to_mk_heartbeat
239
+
240
+ #
241
+ # Returns a new Heartbeat Object
242
+ #
243
+ def initialize()
244
+ end
245
+
246
+ #
247
+ # Execute the command
248
+ #
249
+ def start(options = nil)
250
+ tmp = Tempfile.new('tmp')
251
+ command = option_string() + options.to_s + " 2> " + tmp.path
252
+ success = system(command)
253
+ if success
254
+ begin
255
+ while (line = tmp.readline)
256
+ line.chomp
257
+ selected_string = line
258
+ end
259
+ rescue EOFError
260
+ tmp.close
261
+ end
262
+ return selected_string
263
+ else
264
+ tmp.close!
265
+ return success
266
+ end
267
+ end
268
+
269
+ def config
270
+ option_string()
271
+ end
272
+
273
+ private
274
+
275
+ def option_string()
276
+
277
+ unless @path_to_mk_heartbeat
278
+ ostring = "mk-heartbeat "
279
+ else
280
+ ostring = @path_to_mk_heartbeat + " "
281
+ end
282
+
283
+ self.instance_variables.each do |i|
284
+ tmp_value = self.instance_variable_get "#{i}"
285
+ tmp_string = i.gsub("_", "-").gsub("@", "--")
286
+ unless tmp_string == "--path-to-mk-heartbeat"
287
+ if (tmp_value.is_a? TrueClass) || (tmp_value.is_a? FalseClass)
288
+ ostring += "#{tmp_string} "
289
+ else
290
+ ostring += "#{tmp_string} #{tmp_value} "
291
+ end
292
+ end
293
+ end
294
+
295
+ return ostring
296
+
297
+ end
298
+
299
+ end
300
+
@@ -0,0 +1,164 @@
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
+ # Read queries from a log and analyze how they use indexes.
10
+ #
11
+ # Maatkit::IndexUsage.new( array, str, array)
12
+ #
13
+ class Maatkit::IndexUsage
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_index_usage.conf,/home/joel/.maatkit.conf,/home/joel/.mk_index_usage.conf
31
+
32
+ #
33
+ # short form: -F; type: string
34
+ # Only read mysql options from the given file. You must give an absolute pathname.
35
+ attr_accessor :defaults_file # (No value)
36
+
37
+ #
38
+ # type: Hash; default: non-unique
39
+ # Suggest dropping only these types of unusued indexes.
40
+ # By default mk-index-usage will only suggest to drop unused secondary indexes, not primary or unique
41
+ # indexes. You can specify which types of unused indexes the tool suggests to drop: primary, unique,
42
+ # non-unique, all.
43
+ # A separate "ALTER TABLE" statement for each type is printed. So if you specify "--drop all" and there
44
+ # is a primary key and a non-unique index, the "ALTER TABLE ... DROP" for each will be printed on
45
+ # separate lines.
46
+ attr_accessor :drop # non_unique
47
+
48
+ #
49
+ # Show help and exit.
50
+ attr_accessor :help # TRUE
51
+
52
+ #
53
+ # short form: -h; type: string
54
+ # Connect to host.
55
+ attr_accessor :host # (No value)
56
+
57
+ #
58
+ # short form: -p; type: string
59
+ # Password to use when connecting.
60
+ attr_accessor :password # (No value)
61
+
62
+ #
63
+ # short form: -P; type: int
64
+ # Port number to use for connection.
65
+ attr_accessor :port # (No value)
66
+
67
+ #
68
+ # type: array; default: time,30
69
+ # Print progress reports to STDERR. The value is a comma-separated list with two parts. The first part
70
+ # can be percentage, time, or iterations; the second part specifies how often an update should be
71
+ # printed, in percentage, seconds, or number of iterations.
72
+ attr_accessor :progress # time,30
73
+
74
+ #
75
+ # short form: -q
76
+ # Do not print any warnings. Also disables "--progress".
77
+ attr_accessor :quiet # FALSE
78
+
79
+ #
80
+ # type: string; default: wait_timeout=10000
81
+ # Set these MySQL variables. Immediately after connecting to MySQL, this string will be appended to SET
82
+ # and executed.
83
+ attr_accessor :set_vars # wait_timeout=10000
84
+
85
+ #
86
+ # short form: -S; type: string
87
+ # Socket file to use for connection.
88
+ attr_accessor :socket # (No value)
89
+
90
+ #
91
+ # short form: -u; type: string
92
+ # User for login if not current user.
93
+ attr_accessor :user # (No value)
94
+
95
+ #
96
+ # Show version and exit.
97
+ attr_accessor :version # FALSE
98
+
99
+ #
100
+ # Sets the executable path, otherwise the environment path will be used.
101
+ #
102
+ attr_accessor :path_to_mk_index_usage
103
+
104
+ #
105
+ # Returns a new IndexUsage Object
106
+ #
107
+ def initialize()
108
+ end
109
+
110
+ #
111
+ # Execute the command
112
+ #
113
+ def start(options = nil)
114
+ tmp = Tempfile.new('tmp')
115
+ command = option_string() + options.to_s + " 2> " + tmp.path
116
+ success = system(command)
117
+ if success
118
+ begin
119
+ while (line = tmp.readline)
120
+ line.chomp
121
+ selected_string = line
122
+ end
123
+ rescue EOFError
124
+ tmp.close
125
+ end
126
+ return selected_string
127
+ else
128
+ tmp.close!
129
+ return success
130
+ end
131
+ end
132
+
133
+ def config
134
+ option_string()
135
+ end
136
+
137
+ private
138
+
139
+ def option_string()
140
+
141
+ unless @path_to_mk_index_usage
142
+ ostring = "mk-index-usage "
143
+ else
144
+ ostring = @path_to_mk_index_usage + " "
145
+ end
146
+
147
+ self.instance_variables.each do |i|
148
+ tmp_value = self.instance_variable_get "#{i}"
149
+ tmp_string = i.gsub("_", "-").gsub("@", "--")
150
+ unless tmp_string == "--path-to-mk-index-usage"
151
+ if (tmp_value.is_a? TrueClass) || (tmp_value.is_a? FalseClass)
152
+ ostring += "#{tmp_string} "
153
+ else
154
+ ostring += "#{tmp_string} #{tmp_value} "
155
+ end
156
+ end
157
+ end
158
+
159
+ return ostring
160
+
161
+ end
162
+
163
+ end
164
+