Sha256: 50d459fbd9d3657fa5316668e55a484c53442adcb2e475674afcdb2fedf93a74

Contents?: true

Size: 1.32 KB

Versions: 77

Compression:

Stored size: 1.32 KB

Contents

module Honeybadger
  module Util
    class Stats
      HAS_MEM = File.exist?("/proc/meminfo")
      HAS_LOAD = File.exist?("/proc/loadavg")

      class << self
        def all
          { :mem => memory, :load => load }
        end

        # From https://github.com/bloopletech/webstats/blob/master/server/data_providers/mem_info.rb
        def memory
          out = {}
          if HAS_MEM && (meminfo = run_meminfo)
            out[:total], out[:free], out[:buffers], out[:cached] = meminfo[0..4].map { |l| l =~ /^.*?\: +(.*?) kB$/; ($1.to_i / 1024.0).to_f }
            out[:free_total] = out[:free] + out[:buffers] + out[:cached]
          end
          out
        end

        # From https://github.com/bloopletech/webstats/blob/master/server/data_providers/cpu_info.rb
        def load
          out = {}
          if HAS_LOAD && (loadavg = run_loadavg)
            out[:one], out[:five], out[:fifteen] = loadavg.split(' ', 4).map(&:to_f)
          end
          out
        end

        private

        def run_meminfo
          run { IO.readlines("/proc/meminfo") }
        end

        def run_loadavg
          run { IO.read("/proc/loadavg") }
        end

        def run
          yield
        rescue Errno::ENFILE
          # Catch issues like 'Too many open files in system'
          nil
        end
      end
    end
  end
end

Version data entries

77 entries across 77 versions & 1 rubygems

Version Path
honeybadger-5.24.0 lib/honeybadger/util/stats.rb
honeybadger-5.23.0 lib/honeybadger/util/stats.rb
honeybadger-5.22.0 lib/honeybadger/util/stats.rb
honeybadger-5.21.0 lib/honeybadger/util/stats.rb
honeybadger-5.20.1 lib/honeybadger/util/stats.rb
honeybadger-5.20.0 lib/honeybadger/util/stats.rb
honeybadger-5.19.2 lib/honeybadger/util/stats.rb
honeybadger-5.19.1 lib/honeybadger/util/stats.rb
honeybadger-5.19.0 lib/honeybadger/util/stats.rb
honeybadger-5.18.0 lib/honeybadger/util/stats.rb
honeybadger-5.17.0 lib/honeybadger/util/stats.rb
honeybadger-5.16.0 lib/honeybadger/util/stats.rb
honeybadger-5.15.6 lib/honeybadger/util/stats.rb
honeybadger-5.15.5 lib/honeybadger/util/stats.rb
honeybadger-5.15.4 lib/honeybadger/util/stats.rb
honeybadger-5.15.3 lib/honeybadger/util/stats.rb
honeybadger-5.15.2 lib/honeybadger/util/stats.rb
honeybadger-5.15.1 lib/honeybadger/util/stats.rb
honeybadger-5.15.0 lib/honeybadger/util/stats.rb
honeybadger-5.14.2 lib/honeybadger/util/stats.rb