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.44 lib/reporter/default/stats_base.rb
onering-report-plugins-0.0.43 lib/reporter/default/stats_base.rb
onering-report-plugins-0.0.42 lib/reporter/default/stats_base.rb
onering-report-plugins-0.0.41 lib/reporter/default/stats_base.rb
onering-report-plugins-0.0.40 lib/reporter/default/stats_base.rb
onering-report-plugins-0.0.39 lib/reporter/default/stats_base.rb
onering-report-plugins-0.0.38 lib/reporter/default/stats_base.rb
onering-report-plugins-0.0.37 lib/reporter/default/stats_base.rb
onering-report-plugins-0.0.36 lib/reporter/default/stats_base.rb
onering-report-plugins-0.0.35 lib/reporter/default/stats_base.rb
onering-report-plugins-0.0.34 lib/reporter/default/stats_base.rb
onering-report-plugins-0.0.33 lib/reporter/default/stats_base.rb
onering-report-plugins-0.0.32 lib/reporter/default/stats_base.rb
onering-report-plugins-0.0.31 lib/reporter/default/stats_base.rb
onering-report-plugins-0.0.30 lib/reporter/default/stats_base.rb
onering-report-plugins-0.0.29 lib/reporter/default/stats_base.rb
onering-report-plugins-0.0.28 lib/reporter/default/stats_base.rb
onering-report-plugins-0.0.27 lib/reporter/default/stats_base.rb
onering-report-plugins-0.0.26 lib/reporter/default/stats_base.rb
onering-report-plugins-0.0.25 lib/reporter/default/stats_base.rb