Sha256: 5a6cd48628239b73f687e3e93b75a865def716dd8da3ae6b357d3baab5dc0dfe

Contents?: true

Size: 803 Bytes

Versions: 12

Compression:

Stored size: 803 Bytes

Contents

module NewRelic::Agent
  class CPUSampler
    def initialize
  
      agent = NewRelic::Agent.instance
  
      agent.stats_engine.add_sampled_metric("CPU/User Time") do | stats |
        t = Process.times
        @last_utime ||= t.utime
        
        utime = t.utime
        stats.record_data_point(utime - @last_utime) if (utime - @last_utime) >= 0
        @last_utime = utime
      end
  
      agent.stats_engine.add_sampled_metric("CPU/System Time") do | stats |
        t = Process.times
        @last_stime ||= t.stime
        
        stime = t.stime
        stats.record_data_point(stime - @last_stime) if (stime - @last_stime) >= 0
        @last_stime = stime
      end
    end
  end
end

# CPU sampling like this doesn't work for jruby
NewRelic::Agent::CPUSampler.new unless defined? Java

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
newrelic_rpm-2.8.6 lib/new_relic/agent/samplers/cpu.rb
newrelic_rpm-2.8.0 lib/new_relic/agent/samplers/cpu.rb
newrelic_rpm-2.8.10 lib/new_relic/agent/samplers/cpu.rb
newrelic_rpm-2.8.3 lib/new_relic/agent/samplers/cpu.rb
newrelic_rpm-2.8.5 lib/new_relic/agent/samplers/cpu.rb
newrelic_rpm-2.8.7 lib/new_relic/agent/samplers/cpu.rb
newrelic_rpm-2.8.1 lib/new_relic/agent/samplers/cpu.rb
newrelic_rpm-2.8.11 lib/new_relic/agent/samplers/cpu.rb
newrelic_rpm-2.8.2 lib/new_relic/agent/samplers/cpu.rb
newrelic_rpm-2.8.4 lib/new_relic/agent/samplers/cpu.rb
newrelic_rpm-2.8.8 lib/new_relic/agent/samplers/cpu.rb
newrelic_rpm-2.8.9 lib/new_relic/agent/samplers/cpu.rb