Sha256: 0d5adf4aae78e68fb95c8eef95c3420e60b44632311932aba2b758104140f2f5

Contents?: true

Size: 1.04 KB

Versions: 5

Compression:

Stored size: 1.04 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"
        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
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
ganymed-0.3.4 lib/ganymed/collectors/memory.rb
ganymed-0.3.3 lib/ganymed/collectors/memory.rb
ganymed-0.3.2 lib/ganymed/collectors/memory.rb
ganymed-0.3.1 lib/ganymed/collectors/memory.rb
ganymed-0.3.0 lib/ganymed/collectors/memory.rb