Sha256: 11774baa5dde5c5f7b5b331969f74dd975f24397665cc041f5075cd609989b89
Contents?: true
Size: 1.42 KB
Versions: 1
Compression:
Stored size: 1.42 KB
Contents
# encoding: utf-8 require 'one_apm/agent/sampler' module OneApm module Agent module Samplers class CpuSampler < OneApm::Agent::Sampler attr_reader :last_time named :cpu def initialize @processor_count = OneApm::Agent::SystemInfo.num_logical_processors poll end def self.supported_on_this_platform? # Process.times on JRuby < 1.7.0 reports wall clock elapsed time, not actual cpu time used defined?(JRuby) ? (JRUBY_VERSION >= '1.7.0') : true end def poll now = Time.now t = Process.times if @last_time elapsed = now - @last_time return if elapsed < 1 # Causing some kind of math underflow usertime = t.utime - @last_utime systemtime = t.stime - @last_stime if systemtime >= 0 OneApm::Manager.record_metric("CPU/System Time", systemtime) OneApm::Manager.record_metric("CPU/System/Utilization", systemtime / (elapsed * @processor_count)) end if usertime >= 0 OneApm::Manager.record_metric("CPU/User Time", usertime) OneApm::Manager.record_metric("CPU/User/Utilization", usertime / (elapsed * @processor_count)) end end @last_utime = t.utime @last_stime = t.stime @last_time = now end end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
oneapm_rpm-1.1.3 | lib/one_apm/agent/samplers/cpu_sampler.rb |