module CpuMemoryStats
CpuMemoryStats
will automaticaly choose right system for getting stats author: Ondrej Bartas
Module for geting informations from BSD author: Ondrej Bartas
Module for geting informations from MAC OS X author: Ondrej Bartas
Public Class Methods
get()
click to toggle source
# File lib/cpu-memory-stats.rb, line 6 def self.get unless self.constants.include?(OSDetection.detect) raise ArgumentError, "cpu-memory-stats can not work on this system, uninstall them or write new module for your system" else system = CpuMemoryStats.const_get(OSDetection.detect).new { :cpu => system.cpu, :memory => system.memory, :load => system.load_avg, :cpu_percent => percent(system.cpu), :memory_percent => percent(system.memory), } end end
percent(memory)
click to toggle source
# File lib/cpu-memory-stats.rb, line 21 def self.percent memory maximal = memory.inject(0){|o,i| o+i.last} memory.inject({}){|o,i| o[i.first] = (i.last.to_f / maximal.to_f * 100.0).round(2); o } end