Class: NewRelic::Agent::Samplers::CpuSampler
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 CpuSampler.
6
7
8
9
|
# File 'lib/new_relic/agent/samplers/cpu_sampler.rb', line 6
def initialize
super :cpu
poll
end
|
Instance Attribute Details
#last_time ⇒ Object
Returns the value of attribute last_time.
5
6
7
|
# File 'lib/new_relic/agent/samplers/cpu_sampler.rb', line 5
def last_time
@last_time
end
|
Class Method Details
24
25
26
|
# File 'lib/new_relic/agent/samplers/cpu_sampler.rb', line 24
def self.supported_on_this_platform?
not defined?(JRuby)
end
|
Instance Method Details
#poll ⇒ Object
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
# File 'lib/new_relic/agent/samplers/cpu_sampler.rb', line 28
def poll
now = Time.now
t = Process.times
if @last_time
elapsed = now - @last_time
return if elapsed < 1 num_processors = NewRelic::Control.instance.local_env.processors || 1
usertime = t.utime - @last_utime
systemtime = t.stime - @last_stime
systemtime_stats.record_data_point(systemtime) if systemtime >= 0
usertime_stats.record_data_point(usertime) if usertime >= 0
user_util_stats.record_data_point usertime / (elapsed * num_processors)
system_util_stats.record_data_point systemtime / (elapsed * num_processors)
end
@last_utime = t.utime
@last_stime = t.stime
@last_time = now
end
|
#system_util_stats ⇒ Object
14
15
16
|
# File 'lib/new_relic/agent/samplers/cpu_sampler.rb', line 14
def system_util_stats
stats_engine.get_stats_no_scope("CPU/System/Utilization")
end
|
#systemtime_stats ⇒ Object
20
21
22
|
# File 'lib/new_relic/agent/samplers/cpu_sampler.rb', line 20
def systemtime_stats
stats_engine.get_stats_no_scope("CPU/System Time")
end
|
#user_util_stats ⇒ Object
11
12
13
|
# File 'lib/new_relic/agent/samplers/cpu_sampler.rb', line 11
def user_util_stats
stats_engine.get_stats_no_scope("CPU/User/Utilization")
end
|
#usertime_stats ⇒ Object
17
18
19
|
# File 'lib/new_relic/agent/samplers/cpu_sampler.rb', line 17
def usertime_stats
stats_engine.get_stats_no_scope("CPU/User Time")
end
|