Class: MetOnTheMiddle::Readers::Base

Inherits:
Object
  • Object
show all
Extended by:
SingleForwardable
Includes:
Singleton
Defined in:
lib/met_on_the_middle/readers/base.rb

Overview

Classe base del reader, la quale deve rispondere con la chiave da utilizzare per dare un label al dato inviato (chiave per zabbix)

Direct Known Subclasses

DatabaseTime, RequestCount, TotalTime, ViewTime

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key) ⇒ Base

Returns a new instance of Base.



14
15
16
# File 'lib/met_on_the_middle/readers/base.rb', line 14

def initialize(key)
  @key = key
end

Instance Attribute Details

#keyObject

Returns the value of attribute key.



12
13
14
# File 'lib/met_on_the_middle/readers/base.rb', line 12

def key
  @key
end

Instance Method Details

#match_subscriptionObject

Regular expression to match notifications Serve per attivare la subscription a determinati eventi di ActiveSupport::Notifications



22
23
24
# File 'lib/met_on_the_middle/readers/base.rb', line 22

def match_subscription
  ''
end

#parse(event, request: nil) ⇒ Object

metodo da utilizzare per parsare i dati

Parameters:

  • event (ActiveSupport::Notifications::Event)

    proveniente dalla subscription

  • opts (Hash)

    a customizable set of options

Returns:

  • il valore da salvare ed inviare nei provider di registrazione

Author:

  • Bonetti Marino



37
38
39
# File 'lib/met_on_the_middle/readers/base.rb', line 37

def parse(event, request: nil)
  event.name
end

#register_subscription(tracker) ⇒ Object



46
47
48
49
50
51
52
53
# File 'lib/met_on_the_middle/readers/base.rb', line 46

def register_subscription(tracker)
  ActiveSupport::Notifications.subscribe match_subscription do |*args|
    if not tracker.nil? and not tracker.actual_request.nil?
      event = ActiveSupport::Notifications::Event.new *args
      tracker.add *self.to_key_value(event, request: tracker.actual_request)
    end
  end
end

#to_key_value(event, request: nil) ⇒ Object



41
42
43
# File 'lib/met_on_the_middle/readers/base.rb', line 41

def to_key_value(event, request: nil)
  return @key, parse(event, request: request)
end