Sha256: 680ef756446ec8256182b5578be7846c055755179a3f476fcd9ce557464fbad4

Contents?: true

Size: 1.5 KB

Versions: 12

Compression:

Stored size: 1.5 KB

Contents

# encoding: utf-8
# This file is distributed under New Relic's license terms.
# See https://github.com/newrelic/rpm/blob/master/LICENSE for complete details.

# This module is intended to provide access to information about the host OS and
# [virtual] machine. It intentionally does no caching and maintains no state -
# caching should be handled by clients if needed. Methods should return nil if
# the requested information is unavailable.

require 'rbconfig'

module NewRelic
  module Agent
    module SystemInfo
      def self.ruby_os_identifier
        RbConfig::CONFIG['target_os']
      end

      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

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

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

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
newrelic_rpm-3.7.1.188 lib/new_relic/agent/system_info.rb
newrelic_rpm-3.7.1.182 lib/new_relic/agent/system_info.rb
newrelic_rpm-3.7.1.180 lib/new_relic/agent/system_info.rb
newrelic_rpm-3.7.0.177 lib/new_relic/agent/system_info.rb
newrelic_rpm-3.7.0.174.beta lib/new_relic/agent/system_info.rb
newrelic_rpm-3.6.9.171 lib/new_relic/agent/system_info.rb
newrelic_rpm-3.6.8.168 lib/new_relic/agent/system_info.rb
newrelic_rpm-3.6.8.164 lib/new_relic/agent/system_info.rb
newrelic_rpm-3.6.7.159 lib/new_relic/agent/system_info.rb
newrelic_rpm-3.6.7.159.beta lib/new_relic/agent/system_info.rb
newrelic_rpm-3.6.7.152 lib/new_relic/agent/system_info.rb
newrelic_rpm-3.6.6.147 lib/new_relic/agent/system_info.rb