Sha256: f27b41659aecebbae501f00824565fd1350dee699e8edfd550e151c1ebbeb735

Contents?: true

Size: 751 Bytes

Versions: 1

Compression:

Stored size: 751 Bytes

Contents

module Remon
  module Metrics
    class Oom

      def initialize(log_file)
        @log_file = log_file
        raise Error, "#{log_file} not readable" if not File.readable? log_file
      end

      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

      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

    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
remon-0.1.0 lib/remon/metrics/oom.rb