Sha256: 05da3cbb448dd4dbb23f71c81c9f93b743eca8cb140c917f6ce3c2cde6b1b2ac

Contents?: true

Size: 1.07 KB

Versions: 3

Compression:

Stored size: 1.07 KB

Contents

collect do
  next if not File.readable?('/proc/meminfo')

  # calculate app memory from total
  apps = 0

  File.open('/proc/meminfo') do |file|
    file.each do |line|
      key, value, unit = line.chomp.split
      key.gsub!(/:/, '')
      value = value.to_i * 1024

      case key
      when "MemTotal"
        apps = value
      when "MemFree"
        Metriks.histogram("os.mem.unused").update(value)
        apps -= value
      when "Buffers"
        Metriks.histogram("os.mem.buffers").update(value)
        apps -= value
      when "Cached"
        Metriks.histogram("os.mem.cache").update(value)
        apps -= value
      when "SwapCached"
        Metriks.histogram("os.mem.swap_cache").update(value)
        apps -= value
      when "Slab"
        Metriks.histogram("os.mem.slab_cache").update(value)
        apps -= value
      when "PageTables"
        Metriks.histogram("os.mem.page_tables").update(value)
        apps -= value
      when "Mapped"
        Metriks.histogram("os.mem.mapped").update(value)
      end
    end

    Metriks.histogram("os.mem.apps").update(apps)
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
ganymed-0.4.2 lib/ganymed/collectors/memory.rb
ganymed-0.4.1 lib/ganymed/collectors/memory.rb
ganymed-0.4.0 lib/ganymed/collectors/memory.rb