Class: NewRelic::Agent::Samplers::CpuSampler
Instance Attribute Summary collapse
#id
Class Method Summary
collapse
Instance Method Summary
collapse
enabled?, inherited, named, sampler_classes
Constructor Details
Returns a new instance of CpuSampler.
15
16
17
18
19
20
21
22
23
|
# File 'lib/new_relic/agent/samplers/cpu_sampler.rb', line 15
def initialize
@last_time = nil
@processor_count = NewRelic::Agent::SystemInfo.num_logical_processors
if @processor_count.nil?
NewRelic::Agent.logger.warn('Failed to determine processor count, assuming 1')
@processor_count = 1
end
poll
end
|
Instance Attribute Details
#last_time ⇒ Object
Returns the value of attribute last_time.
11
12
13
|
# File 'lib/new_relic/agent/samplers/cpu_sampler.rb', line 11
def last_time
@last_time
end
|
Class Method Details
41
42
43
44
45
46
47
48
49
|
# File 'lib/new_relic/agent/samplers/cpu_sampler.rb', line 41
def self.supported_on_this_platform?
if defined?(JRuby)
return JRUBY_VERSION >= '1.7.0'
end
true
end
|
Instance Method Details
#poll ⇒ Object
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
# File 'lib/new_relic/agent/samplers/cpu_sampler.rb', line 51
def poll
now = Process.clock_gettime(Process::CLOCK_MONOTONIC)
t = Process.times
if @last_time && t.utime != 0.0 && t.stime != 0.0
elapsed = now - @last_time
return if elapsed < 1
usertime = t.utime - @last_utime
systemtime = t.stime - @last_stime
record_systemtime(systemtime) if systemtime >= 0
record_usertime(usertime) if usertime >= 0
record_user_util(usertime / (elapsed * @processor_count))
record_system_util(systemtime / (elapsed * @processor_count))
end
@last_utime = t.utime
@last_stime = t.stime
@last_time = now
end
|
#record_system_util(value) ⇒ Object
29
30
31
|
# File 'lib/new_relic/agent/samplers/cpu_sampler.rb', line 29
def record_system_util(value)
NewRelic::Agent.record_metric('CPU/System/Utilization', value)
end
|
#record_systemtime(value) ⇒ Object
37
38
39
|
# File 'lib/new_relic/agent/samplers/cpu_sampler.rb', line 37
def record_systemtime(value)
NewRelic::Agent.record_metric('CPU/System Time', value)
end
|
#record_user_util(value) ⇒ Object
25
26
27
|
# File 'lib/new_relic/agent/samplers/cpu_sampler.rb', line 25
def record_user_util(value)
NewRelic::Agent.record_metric('CPU/User/Utilization', value)
end
|
#record_usertime(value) ⇒ Object
33
34
35
|
# File 'lib/new_relic/agent/samplers/cpu_sampler.rb', line 33
def record_usertime(value)
NewRelic::Agent.record_metric('CPU/User Time', value)
end
|