class RequestLogAnalyzer::FileFormat::Postgresql::Request
Public Instance Methods
convert_sql(value, _definition)
click to toggle source
# File lib/request_log_analyzer/file_format/postgresql.rb 36 def convert_sql(value, _definition) 37 # Recreate the full SQL query by joining all the previous parts and this last line 38 sql = every(:query_fragment).join("\n") + value 39 40 # Sanitize an SQL query so that it can be used as a category field. 41 # sql.gsub!(/\/\*.*\*\//, '') # remove comments 42 sql.gsub!(/\s+/, ' ') # remove excessive whitespace 43 sql.gsub!(/"([^"]+)"/, '\1') # remove quotes from field names 44 sql.gsub!(/'\d{4}-\d{2}-\d{2}'/, ':date') # replace dates 45 sql.gsub!(/'\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}'/, ':datetime') # replace timestamps 46 sql.gsub!(/'[^']*'/, ':string') # replace strings 47 sql.gsub!(/\b\d+\b/, ':int') # replace integers 48 sql.gsub!(/(:int,)+:int/, ':ints') # replace multiple ints by a list 49 sql.gsub!(/(:string,)+:string/, ':strings') # replace multiple strings by a list 50 51 sql.lstrip.rstrip 52 end
convert_timestamp(value, _definition)
click to toggle source
Convert the timestamp to an integer
# File lib/request_log_analyzer/file_format/postgresql.rb 59 def convert_timestamp(value, _definition) 60 _, y, m, d, h, i, s = value.split(/(\d\d)-(\d\d)-(\d\d)\s+(\d?\d):(\d\d):(\d\d)/) 61 ('20%s%s%s%s%s%s' % [y, m, d, h.rjust(2, '0'), i, s]).to_i 62 end
host()
click to toggle source
# File lib/request_log_analyzer/file_format/postgresql.rb 54 def host 55 self[:host] == '' || self[:host].nil? ? self[:ip] : self[:host] 56 end