Sha256: 2cf12d96a9f6dcd49ef686dcc15c82fc6068c459bbae0c59199a57a1507112bb

Contents?: true

Size: 988 Bytes

Versions: 2

Compression:

Stored size: 988 Bytes

Contents

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

  # calculate app memory from total
  apps = 0

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

    case key
    when "MemTotal"
      apps = value
    when "MemFree"
      sampler.emit(:gauge, "os.mem.unused", value)
      apps -= value
    when "Buffers"
      sampler.emit(:gauge, "os.mem.buffers", value)
      apps -= value
    when "Cached"
      sampler.emit(:gauge, "os.mem.cache", value)
      apps -= value
    when "SwapCached"
      sampler.emit(:gauge, "os.mem.swap_cache", value)
      apps -= value
    when "Slab"
      sampler.emit(:gauge, "os.mem.slab_cache", value)
      apps -= value
    when "PageTables"
      sampler.emit(:gauge, "os.mem.page_tables", value)
      apps -= value
    when "Mapped"
      sampler.emit(:gauge, "os.mem.mapped", value)
    end
  end

  sampler.emit(:gauge, "os.mem.apps", apps)
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
ganymed-0.2.1 lib/ganymed/collectors/memory.rb
ganymed-0.2.0 lib/ganymed/collectors/memory.rb