Class: RequestLogAnalyzer::FileFormat::Postgresql::Request
- Defined in:
- lib/request_log_analyzer/file_format/postgresql.rb
Instance Attribute Summary
Attributes inherited from Request
#attributes, #file_format, #lines
Instance Method Summary collapse
- #convert_sql(value, _definition) ⇒ Object
-
#convert_timestamp(value, _definition) ⇒ Object
Convert the timestamp to an integer.
- #host ⇒ Object
Methods inherited from Request
#<<, #add_line_hash, #add_parsed_line, #completed?, create, #empty?, #every, #first, #first_lineno, #has_line_type?, #initialize, #last_lineno, #timestamp, #validate
Methods included from Request::Converters
#convert_decimal, #convert_duration, #convert_epoch, #convert_eval, #convert_float, #convert_int, #convert_integer, #convert_nillable_string, #convert_path, #convert_string, #convert_sym, #convert_symbol, #convert_traffic, #convert_value, #sanitize_parameters
Constructor Details
This class inherits a constructor from RequestLogAnalyzer::Request
Instance Method Details
#convert_sql(value, _definition) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/request_log_analyzer/file_format/postgresql.rb', line 36 def convert_sql(value, _definition) # Recreate the full SQL query by joining all the previous parts and this last line sql = every(:query_fragment).join("\n") + value # Sanitize an SQL query so that it can be used as a category field. # sql.gsub!(/\/\*.*\*\//, '') # remove comments sql.gsub!(/\s+/, ' ') # remove excessive whitespace sql.gsub!(/"([^"]+)"/, '\1') # remove quotes from field names sql.gsub!(/'\d{4}-\d{2}-\d{2}'/, ':date') # replace dates sql.gsub!(/'\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}'/, ':datetime') # replace timestamps sql.gsub!(/'[^']*'/, ':string') # replace strings sql.gsub!(/\b\d+\b/, ':int') # replace integers sql.gsub!(/(:int,)+:int/, ':ints') # replace multiple ints by a list sql.gsub!(/(:string,)+:string/, ':strings') # replace multiple strings by a list sql.lstrip.rstrip end |
#convert_timestamp(value, _definition) ⇒ Object
Convert the timestamp to an integer
59 60 61 62 |
# File 'lib/request_log_analyzer/file_format/postgresql.rb', line 59 def (value, _definition) _, y, m, d, h, i, s = value.split(/(\d\d)-(\d\d)-(\d\d)\s+(\d?\d):(\d\d):(\d\d)/) ('20%s%s%s%s%s%s' % [y, m, d, h.rjust(2, '0'), i, s]).to_i end |
#host ⇒ Object
54 55 56 |
# File 'lib/request_log_analyzer/file_format/postgresql.rb', line 54 def host self[:host] == '' || self[:host].nil? ? self[:ip] : self[:host] end |