Sha256: 1a9fead8dd0d0d2d07242fd68539bd7286ed1e1bb398fa94b4c28345ec429dd3

Contents?: true

Size: 634 Bytes

Versions: 3

Compression:

Stored size: 634 Bytes

Contents

module Instrumentation
  # Reads loadavg metric from system
  class LoadAverage
    class << self
      # Input string looks like:
      #   "{ 1.62 1.59 2.03 }"
      # @returns
      #   {:one=>"1.62", :five=>"1.59", :ten=>"2.03"}
      def parse_osx(input)
        %i(one five ten).zip(input.scan(/([0-9\.]+)/).flatten).to_h
      end
    end

    def read
      case system
      when :mac_os
        self.class.parse_osx(last_value)
      else
        raise "Unknown system #{system.inspect}"
      end
    end

    private

    def system
      :mac_os
    end

    def last_value
      `sysctl -n vm.loadavg`
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
process-instrumentation-0.1.3 lib/instrumentation/load_average.rb
process-instrumentation-0.1.2 lib/instrumentation/load_average.rb
process-instrumentation-0.1.1 lib/instrumentation/load_average.rb