Class: NewRelic::Agent::Samplers::MongrelSampler

Inherits:
NewRelic::Agent::Sampler show all
Defined in:
lib/new_relic/agent/samplers/mongrel_sampler.rb

Overview

NewRelic Instrumentation for Mongrel - tracks the queue length of the mongrel server.

Instance Attribute Summary

Attributes inherited from NewRelic::Agent::Sampler

#id, #stats_engine

Instance Method Summary collapse

Methods inherited from NewRelic::Agent::Sampler

inherited, sampler_classes, supported_on_this_platform?, use_harvest_sampler?

Constructor Details

#initializeMongrelSampler

Returns a new instance of MongrelSampler.

Raises:



4
5
6
7
# File 'lib/new_relic/agent/samplers/mongrel_sampler.rb', line 4

def initialize
  super :mongrel
  raise Unsupported, "Mongrel not running" unless NewRelic::Control.instance.local_env.mongrel
end

Instance Method Details

#pollObject



11
12
13
14
15
16
17
18
19
20
21
# File 'lib/new_relic/agent/samplers/mongrel_sampler.rb', line 11

def poll
  mongrel = NewRelic::Control.instance.local_env.mongrel
  if mongrel
    # The mongrel workers list includes workers actively processing requests
    # so you need to subtract what appears to be the active workers from the total
    # number of workers to get the queue size.
    qsize = mongrel.workers.list.length - NewRelic::Agent::BusyCalculator.busy_count
    qsize = 0 if qsize < 0
    queue_stats.record_data_point qsize
  end
end

#queue_statsObject



8
9
10
# File 'lib/new_relic/agent/samplers/mongrel_sampler.rb', line 8

def queue_stats
  stats_engine.get_stats("Mongrel/Queue Length", false)
end