class InfluxDB::Metrics::Model

Constants

INSERT
SELECT_DELETE
UPDATE

Public Instance Methods

handle(_name, start, finish, _id, payload) click to toggle source
# File lib/influxdb/metrics/model.rb, line 14
def handle(_name, start, finish, _id, payload)
  metric = info(start, finish, payload)
  write_point 'sql', metric if metric
rescue => e
  log :debug, "Unable to process sql: #{e.message}"
end
subscribe_to() click to toggle source
# File lib/influxdb/metrics/model.rb, line 10
def subscribe_to
  'sql.active_record'
end

Private Instance Methods

extract(sql) click to toggle source
# File lib/influxdb/metrics/model.rb, line 34
def extract(sql)
  case sql
  when /^SELECT/i then ['select', sql[SELECT_DELETE, 1]]
  when /^INSERT/i then ['insert', sql[INSERT, 1]]
  when /^UPDATE/i then ['update', sql[UPDATE, 1]]
  when /^DELETE/i then ['delete', sql[SELECT_DELETE, 1]]
  end
end
info(start, finish, payload) click to toggle source
# File lib/influxdb/metrics/model.rb, line 23
def info(start, finish, payload)
  action, table = extract(payload[:sql])
  return if action.nil? || table.nil?

  {
    action: action,
    table: (table && table.downcase),
    duration: duration(start, finish)
  }
end