Class: Fluent::Plugin::PostgreSQLSlowLog

Inherits:
Filter
  • Object
show all
Defined in:
lib/fluent/plugin/filter_postgresql_slowlog.rb

Overview

Filters PostgreSQL slow log duration and statements from parsed record.

Examples: duration: 2357.1 ms execute <unnamed>: SELECT * FROM projects duration: 1873.345 ms execute <unnamed>: SELECT COUNT(*) FROM “projects” /*application:sidekiq,correlation_id:d67cae54c169e0cab7d73389e2934f0e,jid:52a1c8a9e4c555ea573f20f0,job_class:Geo::MetricsUpdateWorker*/

Constant Summary collapse

SLOWLOG_REGEXP =
/^duration: (\d+(?:\.\d+)?) ms .*?:\s*(.*)/m.freeze

Instance Method Summary collapse

Instance Method Details

#filter(_tag, _time, record) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/fluent/plugin/filter_postgresql_slowlog.rb', line 20

def filter(_tag, _time, record)
  return record unless record.key?('message')

  # rubocop:disable Style/PerlBackrefs
  if record['message'] =~ SLOWLOG_REGEXP
    record['duration_s'] = $1.to_f / 1000.0
    record[@output_key] = $2
    record.delete('message')
  end
  # rubocop:enable Style/PerlBackrefs

  record
end