class RequestLogAnalyzer::FileFormat::Mysql::Request

Public Instance Methods

convert_sql(value, _definition) click to toggle source
   # File lib/request_log_analyzer/file_format/mysql.rb
68 def convert_sql(value, _definition)
69   # Recreate the full SQL query by joining all the previous parts and this last line
70   sql = every(:query_fragment).join("\n") + value
71 
72   # Sanitize an SQL query so that it can be used as a category field.
73   # sql.gsub!(/\/\*.*\*\//, '')                                       # remove comments
74   sql.gsub!(/\s+/, ' ')                                             # remove excessive whitespace
75   sql.gsub!(/`([^`]+)`/, '\1')                                      # remove quotes from field names
76   sql.gsub!(/'\d{4}-\d{2}-\d{2}'/, ':date')                         # replace dates
77   sql.gsub!(/'\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}'/, ':datetime')   # replace timestamps
78   sql.gsub!(/'[^']*'/, ':string')                                   # replace strings
79   sql.gsub!(/\b\d+\b/, ':int')                                      # replace integers
80   sql.gsub!(/(:int,)+:int/, ':ints')                                # replace multiple ints by a list
81   sql.gsub!(/(:string,)+:string/, ':strings')                       # replace multiple strings by a list
82 
83   sql.strip
84 end
convert_timestamp(value, _definition) click to toggle source

Convert the timestamp to an integer

   # File lib/request_log_analyzer/file_format/mysql.rb
91 def convert_timestamp(value, _definition)
92   _, y, m, d, h, i, s = value.split(/(\d\d)(\d\d)(\d\d)\s+(\d?\d):(\d\d):(\d\d)/)
93   ('20%s%s%s%s%s%s' % [y, m, d, h.rjust(2, '0'), i, s]).to_i
94 end
host() click to toggle source
   # File lib/request_log_analyzer/file_format/mysql.rb
86 def host
87   self[:host] == '' || self[:host].nil? ? self[:ip] : self[:host]
88 end