Class: Haproxy2Rpm::Rpm
- Inherits:
-
Object
- Object
- Haproxy2Rpm::Rpm
- Defined in:
- lib/haproxy2rpm/rpm.rb
Instance Attribute Summary collapse
- #default_route ⇒ Object
-
#queue_time_stats_engine ⇒ Object
Returns the value of attribute queue_time_stats_engine.
-
#routes ⇒ Object
Returns the value of attribute routes.
-
#stats_engine ⇒ Object
Returns the value of attribute stats_engine.
Instance Method Summary collapse
- #config ⇒ Object
- #default_message_parser ⇒ Object
- #default_request_recorder ⇒ Object
-
#initialize(options = {}) ⇒ Rpm
constructor
A new instance of Rpm.
- #message_parser ⇒ Object
- #message_parser=(block) ⇒ Object
- #process_and_send(line) ⇒ Object
- #record_transaction(*args) ⇒ Object
- #request_recorder ⇒ Object
- #request_recorder=(block) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Rpm
Returns a new instance of Rpm.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/haproxy2rpm/rpm.rb', line 7 def initialize( = {}) = {:log => Haproxy2Rpm.logger} [:app_name] = [:app_name] if [:app_name] [:env] = [:env] if [:env] NewRelic::Agent.manual_start @stats_engine = NewRelic::Agent.agent.stats_engine @queue_time_stats_engine = @stats_engine.get_stats_no_scope('WebFrontend/QueueTime') @routes = [:routes] || [] if [:config_file] Haproxy2Rpm.logger.info "Reading configuration from: #{[:config_file]}" content = File.open([:config_file]){|f| f.read } instance_eval(content, [:config_file]) end end |
Instance Attribute Details
#default_route ⇒ Object
26 27 28 |
# File 'lib/haproxy2rpm/rpm.rb', line 26 def default_route @default_route ||= '/default' end |
#queue_time_stats_engine ⇒ Object
Returns the value of attribute queue_time_stats_engine.
4 5 6 |
# File 'lib/haproxy2rpm/rpm.rb', line 4 def queue_time_stats_engine @queue_time_stats_engine end |
#routes ⇒ Object
Returns the value of attribute routes.
4 5 6 |
# File 'lib/haproxy2rpm/rpm.rb', line 4 def routes @routes end |
#stats_engine ⇒ Object
Returns the value of attribute stats_engine.
4 5 6 |
# File 'lib/haproxy2rpm/rpm.rb', line 4 def stats_engine @stats_engine end |
Instance Method Details
#config ⇒ Object
22 23 24 |
# File 'lib/haproxy2rpm/rpm.rb', line 22 def config self end |
#default_message_parser ⇒ Object
39 40 41 42 43 |
# File 'lib/haproxy2rpm/rpm.rb', line 39 def lambda do |line| LineParser.new(line) end end |
#default_request_recorder ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/haproxy2rpm/rpm.rb', line 54 def default_request_recorder lambda do |request| rpm_number_unit = 1000.0 params = { 'metric' => "Controller#{route_for(request.http_path)}" } if request.is_error? params['is_error'] = true params['error_message'] = "#{request.uri} : Status code #{request.status_code}" end record_transaction(request.tr / rpm_number_unit, params) Haproxy2Rpm.logger.debug "RECORDING (transaction) #{request.http_path}: #{params.inspect}" result = queue_time_stats_engine.record_data_point(request.tw / rpm_number_unit) Haproxy2Rpm.logger.debug "RECORDING (data point): wait time #{request.tw}, #{result.inspect}" end end |
#message_parser ⇒ Object
45 46 47 |
# File 'lib/haproxy2rpm/rpm.rb', line 45 def @message_parser ||= end |
#message_parser=(block) ⇒ Object
49 50 51 52 |
# File 'lib/haproxy2rpm/rpm.rb', line 49 def (block) Haproxy2Rpm.logger.debug "Installing custom parser" @message_parser = block end |
#process_and_send(line) ⇒ Object
30 31 32 33 34 35 36 37 |
# File 'lib/haproxy2rpm/rpm.rb', line 30 def process_and_send(line) begin = .call(line) request_recorder.call() rescue URI::InvalidURIError Haproxy2Rpm.logger.warn "Parser returned an empty message from line #{line}" end end |
#record_transaction(*args) ⇒ Object
83 84 85 |
# File 'lib/haproxy2rpm/rpm.rb', line 83 def record_transaction(*args) NewRelic::Agent.record_transaction(*args) end |
#request_recorder ⇒ Object
74 75 76 |
# File 'lib/haproxy2rpm/rpm.rb', line 74 def request_recorder @request_recorder ||= default_request_recorder end |
#request_recorder=(block) ⇒ Object
78 79 80 81 |
# File 'lib/haproxy2rpm/rpm.rb', line 78 def request_recorder=(block) Haproxy2Rpm.logger.debug "Installing custom recorder" @request_recorder = block end |