Class: Maatkit::ErrorLog
- Inherits:
-
Object
- Object
- Maatkit::ErrorLog
- Defined in:
- lib/maatkit-ruby/mk-error-log.rb
Overview
Find new and different MySQL error log entries.
Maatkit::ErrorLog.new( array, str, array)
Instance Attribute Summary collapse
-
#ask_pass ⇒ Object
Prompt for a password when connecting to MySQL.
-
#charset ⇒ Object
short form: -A; type: string Default character set.
-
#config ⇒ Object
type: Array Read this comma-separated list of config files; if specified, this must be the first option on the command line.
-
#continue_on_error ⇒ Object
default: yes Continue parsing even if there is an error.
-
#defaults_file ⇒ Object
short form: -F; type: string Only read mysql options from the given file.
-
#help ⇒ Object
Show help and exit.
-
#host ⇒ Object
short form: -h; type: string Connect to host.
-
#known_patterns ⇒ Object
default: yes Load known, built-in patterns.
-
#load_patterns ⇒ Object
type: string Load a list of known patterns from this file.
-
#password ⇒ Object
short form: -p; type: string Password to use when connecting.
-
#path_to_mk_error_log ⇒ Object
Sets the executable path, otherwise the environment path will be used.
-
#pid ⇒ Object
type: string Create the given PID file when daemonized.
-
#port ⇒ Object
short form: -P; type: int Port number to use for connection.
-
#resume ⇒ Object
type: string Read and write resume position to this file; resume parsing from last position.
-
#save_patterns ⇒ Object
type: string After running save all new and old patterns to this file.
-
#set_vars ⇒ Object
type: string; default: wait_timeout=10000 Set these MySQL variables.
-
#since ⇒ Object
type: string Parse only events newer than this value (parse events since this date).
-
#socket ⇒ Object
short form: -S; type: string Socket file to use for connection.
-
#until ⇒ Object
type: string Parse only events older than this value (parse events until this date).
-
#user ⇒ Object
short form: -u; type: string User for login if not current user.
-
#version ⇒ Object
Show version and exit.
Instance Method Summary collapse
-
#initialize ⇒ ErrorLog
constructor
Returns a new ErrorLog Object.
-
#start(options = nil) ⇒ Object
Execute the command.
Constructor Details
#initialize ⇒ ErrorLog
Returns a new ErrorLog Object
183 184 |
# File 'lib/maatkit-ruby/mk-error-log.rb', line 183 def initialize() end |
Instance Attribute Details
#ask_pass ⇒ Object
Prompt for a password when connecting to MySQL.
17 18 19 |
# File 'lib/maatkit-ruby/mk-error-log.rb', line 17 def ask_pass @ask_pass end |
#charset ⇒ Object
short form: -A; type: string Default character set. If the value is utf8, sets Perl’s binmode on STDOUT to utf8, passes the mysql_enable_utf8 option to DBD::mysql, and runs SET NAMES UTF8 after connecting to MySQL. Any other value sets binmode on STDOUT without the utf8 layer, and runs SET NAMES after connecting to MySQL.
24 25 26 |
# File 'lib/maatkit-ruby/mk-error-log.rb', line 24 def charset @charset end |
#config ⇒ Object
type: Array Read this comma-separated list of config files; if specified, this must be the first option on the command line.
30 31 32 |
# File 'lib/maatkit-ruby/mk-error-log.rb', line 30 def config @config end |
#continue_on_error ⇒ Object
default: yes Continue parsing even if there is an error.
35 36 37 |
# File 'lib/maatkit-ruby/mk-error-log.rb', line 35 def continue_on_error @continue_on_error end |
#defaults_file ⇒ Object
short form: -F; type: string Only read mysql options from the given file. You must give an absolute pathname.
40 41 42 |
# File 'lib/maatkit-ruby/mk-error-log.rb', line 40 def defaults_file @defaults_file end |
#help ⇒ Object
Show help and exit.
44 45 46 |
# File 'lib/maatkit-ruby/mk-error-log.rb', line 44 def help @help end |
#host ⇒ Object
short form: -h; type: string Connect to host.
49 50 51 |
# File 'lib/maatkit-ruby/mk-error-log.rb', line 49 def host @host end |
#known_patterns ⇒ Object
default: yes Load known, built-in patterns. mk-error-log has a built-in list of known patterns. This are normally loaded by default, but if you don’t want them to be used you can disable them from being loaded by specifying “–no-known-patterns”.
56 57 58 |
# File 'lib/maatkit-ruby/mk-error-log.rb', line 56 def known_patterns @known_patterns end |
#load_patterns ⇒ Object
type: string Load a list of known patterns from this file. Patterns in the file should be formatted like this:
name1
level1
pattern1
nameN
levelN
patternN
Each pattern has three parts: name, level and regex pattern. Patterns are separated by a blank line. A pattern’s name is what is printed under the Message column in the “OUTPUT”. Likewise, its level is printed under the Level column. The regex pattern is what mk-error-log uses to match this pattern. Any Perl regular expression should be valid. Here is a simple example:
InnoDB: The first specified data file did not exist!
info
InnoDB: The first specified data file \S+
InnoDB: Rolling back of trx complete
info
InnoDB: Rolling back of trx id .*?complete
See also “–save-patterns”.
80 81 82 |
# File 'lib/maatkit-ruby/mk-error-log.rb', line 80 def load_patterns @load_patterns end |
#password ⇒ Object
short form: -p; type: string Password to use when connecting.
85 86 87 |
# File 'lib/maatkit-ruby/mk-error-log.rb', line 85 def password @password end |
#path_to_mk_error_log ⇒ Object
Sets the executable path, otherwise the environment path will be used.
178 179 180 |
# File 'lib/maatkit-ruby/mk-error-log.rb', line 178 def path_to_mk_error_log @path_to_mk_error_log end |
#pid ⇒ Object
type: string Create the given PID file when daemonized. The file contains the process ID of the daemonized instance. The PID file is removed when the daemonized instance exits. The program checks for the existence of the PID file when starting; if it exists and the process with the matching PID exists, the program exits.
93 94 95 |
# File 'lib/maatkit-ruby/mk-error-log.rb', line 93 def pid @pid end |
#port ⇒ Object
short form: -P; type: int Port number to use for connection.
98 99 100 |
# File 'lib/maatkit-ruby/mk-error-log.rb', line 98 def port @port end |
#resume ⇒ Object
type: string Read and write resume position to this file; resume parsing from last position. By default mk-error-log parses an error logs from start (pos 0) to finish. This option allows the tool to start parsing an error log from where it last ended as long as the file has the same name and inode (e.g. it hasn’t been rotated) and its size is larger. If the log file’s name or inode is different, then a new resume file is started and the old resume file is saved with the old error log’s inode appended to its file name. If the log file’s size is smaller (e.g. the log was truncated), then parsing begins from the start. A resume file is a simple, four line text file like:
file:/path/to/err.log
inode:12345
pos:67890
size:987100
The resume file is read at startup and updated when mk-error-log finishes parsing the log. Note that CTRL-C prevents the resume file from being updated. If the resume file doesn’t exist it is created. A line is printed before the main report which tells when and at what position parsing began for the error log if it was resumed.
119 120 121 |
# File 'lib/maatkit-ruby/mk-error-log.rb', line 119 def resume @resume end |
#save_patterns ⇒ Object
type: string After running save all new and old patterns to this file. This option causes mk-error-log to save every pattern it has to the file. This file can be used for subsequent runs with “–load-patterns”. The patterns are saved in descending order of frequency, so the most frequent patterns are at top.
127 128 129 |
# File 'lib/maatkit-ruby/mk-error-log.rb', line 127 def save_patterns @save_patterns end |
#set_vars ⇒ Object
type: string; default: wait_timeout=10000 Set these MySQL variables. Immediately after connecting to MySQL, this string will be appended to SET and executed.
133 134 135 |
# File 'lib/maatkit-ruby/mk-error-log.rb', line 133 def set_vars @set_vars end |
#since ⇒ Object
type: string Parse only events newer than this value (parse events since this date). This option allows you to ignore events older than a certain value and parse only those events which are more recent than the value. The value can be several types:
* Simple time value N with optional suffix: N[shmd], where
# s=seconds, h=hours, m=minutes, d=days (default s if no suffix
# given); this is like saying "since N[shmd] ago"
* Full date with optional hours:minutes:seconds: YYYY-MM-DD [HH:MM::SS]
* Short, MySQL-style date: YYMMDD [HH:MM:SS]
Events are assumed to be in chronological–older events at the beginning of the log and newer events at the end of the log. “–since” is strict: it ignores all events until one is found that is new enough. Therefore, if the events are not consistently timestamped, some may be ignored which are actually new enough. See also “–until”.
150 151 152 |
# File 'lib/maatkit-ruby/mk-error-log.rb', line 150 def since @since end |
#socket ⇒ Object
short form: -S; type: string Socket file to use for connection.
155 156 157 |
# File 'lib/maatkit-ruby/mk-error-log.rb', line 155 def socket @socket end |
#until ⇒ Object
type: string Parse only events older than this value (parse events until this date). This option allows you to ignore events newer than a certain value and parse only those events which are older than the value. The value can be one of the same types listed for “–since”. Unlike “–since”, “–until” is not strict: all events are parsed until one has a timestamp that is equal to or greater than “–until”. Then all subsequent events are ignored.
164 165 166 |
# File 'lib/maatkit-ruby/mk-error-log.rb', line 164 def until @until end |
#user ⇒ Object
short form: -u; type: string User for login if not current user.
169 170 171 |
# File 'lib/maatkit-ruby/mk-error-log.rb', line 169 def user @user end |
#version ⇒ Object
Show version and exit.
173 174 175 |
# File 'lib/maatkit-ruby/mk-error-log.rb', line 173 def version @version end |
Instance Method Details
#start(options = nil) ⇒ Object
Execute the command
189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 |
# File 'lib/maatkit-ruby/mk-error-log.rb', line 189 def start( = nil) tmp = Tempfile.new('tmp') command = option_string() + .to_s + " 2> " + tmp.path success = system(command) if success begin while (line = tmp.readline) line.chomp selected_string = line end rescue EOFError tmp.close end return selected_string else tmp.close! return success end end |