Sha256: ff45e961c00fff109db7425226e1c9b6aea819ea83d60cdd26b927d95d074150

Contents?: true

Size: 1.34 KB

Versions: 42

Compression:

Stored size: 1.34 KB

Contents

# Onering Collector - Base Statistics plugin
#   provides basic system statistics and hardware profile to the Onering API
#

report do
# ------------------------------------------------------------------------------
# memory
#
  stats_mem = {}

  File.open("/proc/meminfo").each do |line|
    case line
    when /^MemTotal:\s+(\d+)/
      stats_mem[:total] = ($1.to_i * 1024)
    when /^SwapTotal:\s+(\d+)/
      stats_mem[:swap] = ($1.to_i * 1024)
    end
  end


# ------------------------------------------------------------------------------
# cpu
#
  stats_cpu = {
    :count => 0,
    :processors => []
  }

  current_cpu = nil

  File.open("/proc/cpuinfo").each do |line|
    case line
    when /processor\s+:\s(.+)/
      current_cpu = $1.to_i
      stats_cpu[:count] += 1
      stats_cpu[:processors][current_cpu] = {
        :number => current_cpu
      }
    when /cpu MHz\s+:\s(.+)/
      stats_cpu[:processors][current_cpu][:speed] = $1.to_f
    end
  end


# ------------------------------------------------------------------------------
# set stat properties
#
  stat :memory, stats_mem
  stat :cpu, ({
    'count'    => Facter.value('processorcount').to_i,
    'physical' => Facter.value('physicalprocessorcount').to_i,
    'speed'    => stats_cpu[:processors].collect{|i| i[:speed] }.compact.uniq.sort{|a,b| a.to_f <=> b.to_f }.last.to_f
  } rescue nil)
end

Version data entries

42 entries across 42 versions & 1 rubygems

Version Path
onering-report-plugins-0.0.24 lib/reporter/default/stats_base.rb
onering-report-plugins-0.0.23 lib/reporter/default/stats_base.rb
onering-report-plugins-0.0.22 lib/reporter/default/stats_base.rb
onering-report-plugins-0.0.21 lib/reporter/default/stats_base.rb
onering-report-plugins-0.0.20 lib/reporter/default/stats_base.rb
onering-report-plugins-0.0.19 lib/reporter/default/stats_base.rb
onering-report-plugins-0.0.18 lib/reporter/default/stats_base.rb
onering-report-plugins-0.0.17 lib/reporter/default/stats_base.rb
onering-report-plugins-0.0.16 lib/reporter/default/stats_base.rb
onering-report-plugins-0.0.15 lib/reporter/default/stats_base.rb
onering-report-plugins-0.0.14 lib/reporter/default/stats_base.rb
onering-report-plugins-0.0.13 lib/reporter/default/stats_base.rb
onering-report-plugins-0.0.12 lib/reporter/default/stats_base.rb
onering-report-plugins-0.0.11 lib/reporter/default/stats_base.rb
onering-report-plugins-0.0.10 lib/reporter/default/stats_base.rb
onering-report-plugins-0.0.9 lib/reporter/default/stats_base.rb
onering-report-plugins-0.0.8 lib/reporter/default/stats_base.rb
onering-report-plugins-0.0.7 lib/reporter/default/stats_base.rb
onering-report-plugins-0.0.6 lib/reporter/default/stats_base.rb
onering-report-plugins-0.0.5 lib/reporter/default/stats_base.rb