Sha256: 71218f66101af68c71f3fb8a6bf4a190375a5b7bad2cafc720449feb1bf63d9b
Contents?: true
Size: 1.17 KB
Versions: 3
Compression:
Stored size: 1.17 KB
Contents
module Dexter class LogParser REGEX = /duration: (\d+\.\d+) ms (statement|execute <unnamed>): (.+)/ LINE_SEPERATOR = ": ".freeze def initialize(logfile, collector) @logfile = logfile @collector = collector end def perform active_line = nil duration = nil each_line do |line| if active_line if line.include?(LINE_SEPERATOR) process_entry(active_line, duration) active_line = nil else active_line << line end end if !active_line && m = REGEX.match(line.chomp) duration = m[1].to_f active_line = m[3] end end process_entry(active_line, duration) if active_line end private def each_line if @logfile == STDIN STDIN.each_line do |line| yield line end else begin File.foreach(@logfile) do |line| yield line end rescue Errno::ENOENT abort "Log file not found" end end end def process_entry(query, duration) @collector.add(query, duration) if query =~ /SELECT/i end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
pgdexter-0.1.4 | lib/dexter/log_parser.rb |
pgdexter-0.1.3 | lib/dexter/log_parser.rb |
pgdexter-0.1.2 | lib/dexter/log_parser.rb |