Class: Honeybadger::Util::Stats

Inherits:
Object
  • Object
show all
Defined in:
lib/honeybadger/util/stats.rb

Constant Summary collapse

HAS_MEM =
File.exists?("/proc/meminfo")
HAS_LOAD =
File.exists?("/proc/loadavg")

Class Method Summary collapse

Class Method Details

.allObject



8
9
10
# File 'lib/honeybadger/util/stats.rb', line 8

def all
  { :mem => memory, :load => load }
end

.loadObject



23
24
25
26
27
28
29
# File 'lib/honeybadger/util/stats.rb', line 23

def load
  out = {}
  if HAS_LOAD && (loadavg = run_loadavg)
    out[:one], out[:five], out[:fifteen] = loadavg.split(' ', 4).map(&:to_f)
  end
  out
end

.memoryObject



13
14
15
16
17
18
19
20
# File 'lib/honeybadger/util/stats.rb', line 13

def memory
  out = {}
  if HAS_MEM && (meminfo = run_meminfo)
    out[:total], out[:free], out[:buffers], out[:cached] = meminfo[0..4].map { |l| l =~ /^.*?\: +(.*?) kB$/; ($1.to_i / 1024.0).to_f }
    out[:free_total] = out[:free] + out[:buffers] + out[:cached]
  end
  out
end