Class: NewRelic::Agent::Samplers::MemorySampler
Defined Under Namespace
Classes: Base, JavaHeapSampler, ProcStatus, ShellPS
Instance Attribute Summary collapse
#id, #stats_engine
Class Method Summary
collapse
Instance Method Summary
collapse
inherited, sampler_classes, use_harvest_sampler?
Constructor Details
Returns a new instance of MemorySampler.
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
# File 'lib/new_relic/agent/samplers/memory_sampler.rb', line 8
def initialize
super :memory
if defined? JRuby
@sampler = JavaHeapSampler.new
elsif platform =~ /linux/
@sampler = ProcStatus.new
if !@sampler.can_run?
NewRelic::Agent.instance.warn.debug "Error attempting to use /proc/#{$$}/status file for reading memory. Using ps command instead."
@sampler = ShellPS.new("ps -o rsz")
else
NewRelic::Agent.instance.log.debug "Using /proc/#{$$}/status for reading process memory."
end
elsif platform =~ /darwin9/ @sampler = ShellPS.new("ps -o rsz")
elsif platform =~ /darwin10/ @sampler = ShellPS.new("ps -o rss")
elsif platform =~ /freebsd/
@sampler = ShellPS.new("ps -o rss")
elsif platform =~ /solaris/
@sampler = ShellPS.new("/usr/bin/ps -o rss -p")
end
raise Unsupported, "Unsupported platform for getting memory: #{platform}" if @sampler.nil?
raise Unsupported, "Unable to run #{@sampler}" unless @sampler.can_run?
end
|
Instance Attribute Details
#sampler ⇒ Object
Returns the value of attribute sampler.
6
7
8
|
# File 'lib/new_relic/agent/samplers/memory_sampler.rb', line 6
def sampler
@sampler
end
|
Class Method Details
39
40
41
42
43
44
45
|
# File 'lib/new_relic/agent/samplers/memory_sampler.rb', line 39
def self.platform
if RUBY_PLATFORM =~ /java/
%x[uname -s].downcase
else
RUBY_PLATFORM.downcase
end
end
|
35
36
37
|
# File 'lib/new_relic/agent/samplers/memory_sampler.rb', line 35
def self.supported_on_this_platform?
defined?(JRuby) or platform =~ /linux|darwin9|darwin10|freebsd|solaris/
end
|
Instance Method Details
#poll ⇒ Object
53
54
55
56
57
|
# File 'lib/new_relic/agent/samplers/memory_sampler.rb', line 53
def poll
sample = @sampler.get_sample
stats.record_data_point sample if sample
stats
end
|
#stats ⇒ Object
50
51
52
|
# File 'lib/new_relic/agent/samplers/memory_sampler.rb', line 50
def stats
stats_engine.get_stats("Memory/Physical", false)
end
|