Class: PostgreSQLParser

Inherits:
Parser
  • Object
show all
Defined in:
lib/gl_tail/parsers/postgresql.rb

Overview

Parser which handles PostgreSQL logs

Instance Attribute Summary

Attributes inherited from Parser

#source

Instance Method Summary collapse

Methods inherited from Parser

#add_activity, #add_event, inherited, #initialize, registry, #server

Constructor Details

This class inherits a constructor from Parser

Instance Method Details

#parse(line) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/gl_tail/parsers/postgresql.rb', line 9

def parse( line )
  # here's an example parser for postgres log files; adjust accordingly for different logfile setups.
  #
  # postgresql.conf:
  #    log_line_prefix = '[%d, %t] '
  #    log_connections = on
  #    log_disconnections = on
  #    log_duration = on
  #    log_statement = 'all'

  _, database, datetime, activity, description = /^\[(.*), (.* .* .*)\] LOG:  ([a-zA-Z0-9\s]*): (.*)/.match(line).to_a

  unless _
    _, database, datetime, activity, description = /postgres\[\d+\]: \[\d+-\d+\] \[(.*), (.* .* .*)\] LOG:  ([a-zA-Z0-9\s]*): (.*)/.match(line).to_a
    syslog = true if _
  end

  if database
    add_activity(:block => 'database', :name => database, :size => 0.2)
  else
    _, datetime, activity, description = /(.* .* .*) LOG:  ([a-zA-Z0-9\s]*): (.*)/.match(line).to_a
  end

  if activity
    activity = 'vacuum' if(description.include?('vacuum') || activity == 'autovacuum')
    case activity
    when 'duration'
      add_activity(:block => 'database', :name => 'duration', :size => description.to_f / 100.0)
    when 'statement'
      add_activity(:block => 'database', :name => 'activity', :size => 0.2)
    when 'connection authorized', 'disconnection'
      add_activity(:block => 'database', :name => 'login/logout', :size => 0.2)
    when 'vacuum'
      add_event(:block => 'database', :name => 'vacuum', :message => description, :update_stats => true, :color => [1.0, 1.0, 0.0, 1.0])
    end
  end

end