Sha256: bf27baac37f2e9959cc6350a28d76e563b0a9b64cad35df50849756828331fd2

Contents?: true

Size: 634 Bytes

Versions: 9

Compression:

Stored size: 634 Bytes

Contents

module LitmusPaper
  module Metric
    class CPULoad
      def initialize(weight)
        @weight = weight
      end

      def current_health
        [@weight - (@weight * load_average / processor_count), 1].max
      end

      def processor_count
        @processor_count ||= File.readlines('/proc/cpuinfo').reduce(0) do |memo, line|
          if line =~ /^processor/
            memo + 1
          else
            memo
          end
        end

      end

      def load_average
        File.read('/proc/loadavg').split(' ').first.to_f
      end

      def to_s
        "Metric::CPULoad(#{@weight})"
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
litmus_paper-1.4.2 lib/litmus_paper/metric/cpu_load.rb
litmus_paper-1.4.1 lib/litmus_paper/metric/cpu_load.rb
litmus_paper-1.3.0 lib/litmus_paper/metric/cpu_load.rb
litmus_paper-1.2.0 lib/litmus_paper/metric/cpu_load.rb
litmus_paper-1.1.1 lib/litmus_paper/metric/cpu_load.rb
litmus_paper-1.1.0 lib/litmus_paper/metric/cpu_load.rb
litmus_paper-1.0.0 lib/litmus_paper/metric/cpu_load.rb
litmus_paper-0.9.9 lib/litmus_paper/metric/cpu_load.rb
litmus_paper-0.9.7 lib/litmus_paper/metric/cpu_load.rb