Module: NewRelic::Agent::SystemInfo

Defined in:
lib/new_relic/agent/system_info.rb

Class Method Summary collapse

Class Method Details

.os_versionObject



49
50
51
# File 'lib/new_relic/agent/system_info.rb', line 49

def self.os_version
  `uname -v` rescue nil
end

.processor_archObject



45
46
47
# File 'lib/new_relic/agent/system_info.rb', line 45

def self.processor_arch
  RbConfig::CONFIG['target_cpu']
end

.processor_countObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/new_relic/agent/system_info.rb', line 19

def self.processor_count
  case ruby_os_identifier
  when /darwin/, /freebsd/
    `sysctl -n hw.ncpu`.to_i
  when /linux/
    cpuinfo = ''
    proc_file = '/proc/cpuinfo'
    File.open(proc_file) do |f|
      loop do
        begin
          cpuinfo << f.read_nonblock(4096).strip
        rescue EOFError
          break
        rescue Errno::EWOULDBLOCK, Errno::EAGAIN
          cpuinfo = ''
          break # don't select file handle, just give up
        end
      end
    end
    processors = cpuinfo.split("\n").select {|line| line =~ /^processor\s*:/ }.size
    processors == 0 ? nil : processors
  end
rescue
  nil
end

.ruby_os_identifierObject



15
16
17
# File 'lib/new_relic/agent/system_info.rb', line 15

def self.ruby_os_identifier
  RbConfig::CONFIG['target_os']
end