Sha256: 7ba06445948c922f7d1cdad868ed796f1b85ac53382371fa829542742b0c73c3

Contents?: true

Size: 657 Bytes

Versions: 23

Compression:

Stored size: 657 Bytes

Contents

# -*- encoding: utf-8 -*-
module Bluepill
  module ProcessConditions
    class MemUsage < ProcessCondition
      MB = 1024 ** 2
      FORMAT_STR = "%d%s"
      MB_LABEL = "MB"
      KB_LABEL = "KB"

      def initialize(options = {})
        @below = options[:below]
      end

      def run(pid)
        # rss is on the 5th col
        System.memory_usage(pid).to_f
      end

      def check(value)
        value.kilobytes < @below
      end

      def format_value(value)
        if value.kilobytes >= MB
          FORMAT_STR % [(value / 1024).round, MB_LABEL]
        else
          FORMAT_STR % [value, KB_LABEL]
        end
      end
    end
  end
end

Version data entries

23 entries across 23 versions & 5 rubygems

Version Path
bluepill-rwgps-0.0.63 lib/bluepill/process_conditions/mem_usage.rb
bluepill-rwgps-0.0.62 lib/bluepill/process_conditions/mem_usage.rb
bluepill-rwgps-0.0.61 lib/bluepill/process_conditions/mem_usage.rb
bluepill-rwgps-0.0.60 lib/bluepill/process_conditions/mem_usage.rb
kostya-bluepill-0.0.60.3 lib/bluepill/process_conditions/mem_usage.rb
kostya-bluepill-0.0.60.2 lib/bluepill/process_conditions/mem_usage.rb
kostya-bluepill-0.0.60.1 lib/bluepill/process_conditions/mem_usage.rb
skalar-bluepill-0.0.60.1 lib/bluepill/process_conditions/mem_usage.rb
bluepill-0.0.60 lib/bluepill/process_conditions/mem_usage.rb
bluepill-0.0.59 lib/bluepill/process_conditions/mem_usage.rb
bluepill-0.0.58 lib/bluepill/process_conditions/mem_usage.rb
bluepill-0.0.57 lib/bluepill/process_conditions/mem_usage.rb
bluepill-0.0.56 lib/bluepill/process_conditions/mem_usage.rb
bluepill-0.0.55 lib/bluepill/process_conditions/mem_usage.rb
bluepill-0.0.54 lib/bluepill/process_conditions/mem_usage.rb
bluepill-0.0.53 lib/bluepill/process_conditions/mem_usage.rb
bluepill-0.0.52 lib/bluepill/process_conditions/mem_usage.rb
ryansch-bluepill-0.0.53 lib/bluepill/process_conditions/mem_usage.rb
bluepill-0.0.51 lib/bluepill/process_conditions/mem_usage.rb
bluepill-0.0.50 lib/bluepill/process_conditions/mem_usage.rb