class Remon::Metrics::Oom

Public Class Methods

new(log_file) click to toggle source
# File lib/remon/metrics/oom.rb, line 5
def initialize(log_file)
  @log_file = log_file
  raise Error, "#{log_file} not readable" if not File.readable? log_file
end

Public Instance Methods

stats() click to toggle source
# File lib/remon/metrics/oom.rb, line 10
def stats
  counts = oom_counts
  total_count = counts.values.reduce(&:+)
  todays_count = counts[Time.now.strftime("%b%e")]
  {today: todays_count, total: total_count}
end

Private Instance Methods

oom_counts() click to toggle source
# File lib/remon/metrics/oom.rb, line 19
def oom_counts
  counts = Hash.new(0)
  IO.popen "grep 'invoked oom-killer' #{@log_file} | awk '{print $1 $2}' | uniq -c" do |f|
    f.each_line do |line|
      split = line.strip.split
      counts[split[1]] = split[0].to_i
    end
  end
  counts
end