<?xml version="1.0" encoding="UTF-8"?>
<plugin-url>
  <approved type="boolean">true</approved>
  <author>Eric Lindvall</author>
  <cached-tag-list>memory</cached-tag-list>
  <canonical-name>memory</canonical-name>
  <code>class MemoryProfiler &lt; Scout::Plugin
  def build_report
    mem_info = {}
    `cat /proc/meminfo`.each_line do |line|
      _, key, value = *line.match(/^(\w+):\s+(\d+)\s/)
      mem_info[key] = value.to_i
    end
    
    # memory info is empty - operating system may not support it (why doesn't an exception get raised earlier on mac osx?)
    if mem_info.empty?
      raise &quot;No such file or directory&quot;
    end
    
    mem_total = mem_info['MemTotal'] / 1024
    mem_free = (mem_info['MemFree'] + mem_info['Buffers'] + mem_info['Cached']) / 1024
    mem_used = mem_total - mem_free
    mem_percent_used = (mem_used / mem_total.to_f * 100).to_i

    swap_total = mem_info['SwapTotal'] / 1024
    swap_free = mem_info['SwapFree'] / 1024
    swap_used = swap_total - swap_free
    unless swap_total == 0    
      swap_percent_used = (swap_used / swap_total.to_f * 100).to_i
    end
    
    # will be passed at the end to report to Scout
    report_data = Hash.new

    report_data['Memory Total'] = mem_total
    report_data['Memory Used'] = mem_used
    report_data['% Memory Used'] = mem_percent_used

    report_data['Swap Total'] = swap_total
    report_data['Swap Used'] = swap_used
    unless  swap_total == 0   
      report_data['% Swap Used'] = swap_percent_used
    end
    report(report_data)
        
  rescue Exception =&gt; e
    if e.message =~ /No such file or directory/
      error('Unable to find /proc/meminfo',%Q(Unable to find /proc/meminfo. Please ensure your operationg system supports procfs:
         http://en.wikipedia.org/wiki/Procfs)
      )
    else
      raise
    end
  end
end
</code>
  <created-at type="datetime">2008-04-17T07:36:17-07:00</created-at>
  <default-triggers type="yaml" nil="true"></default-triggers>
  <description>Returns a profile of the system's memory usage (Swap Total, Swap Used, Swap Used, Memory Total, Memory Used, and Memory Used).
&lt;br/&gt;&lt;br/&gt;
*Compatibility*

Requires &quot;procfs&quot;:http://en.wikipedia.org/wiki/Procfs, which is supported under Solaris, BSD, and Linux:


</description>
  <featured type="boolean">false</featured>
  <id type="integer">15</id>
  <metadata type="yaml">--- |
metadata:
  Memory Total:
    units: MB
    precision: 0
    larger_is_better: true
  Memory Used:
    units: MB
    precision: 0
  % Memory Used:
    units: %
    precision: 0
  Swap Total:
    units: MB
    precision: 0
  Swap Used:
    units: MB
    precision: 0
  % Swap Used:
    units: %
    precision: 0

triggers:
  - type: peak
    dname: % Swap Used
    max_value: 50

</metadata>
  <name>Memory Profiler</name>
  <plugins-count type="integer">477</plugins-count>
  <rating-avg type="decimal">5.0</rating-avg>
  <rating-count type="integer">3</rating-count>
  <rating-total type="integer">15</rating-total>
  <readme>Memory Profiler Plugin
=====================
Created by Eric Lindvall 

Compatibility 
-------------
Requires [procfs](http://en.wikipedia.org/wiki/Procfs), which is supported under Solaris, BSD, and Linux:

Functionality
-------------
Returns a profile of the system's memory usage:
* Swap Total
* Swap Used
* % Swap Used
* Memory Total
* Memory Used
* % Memory Used</readme>
  <schema type="yaml" nil="true"></schema>
  <scout-version type="integer">3</scout-version>
  <short-description>Returns a profile of the system's memory usage (memory used, % memory used, swap used, % swap used, etc). Requires procfs.</short-description>
  <tested-platforms>linux</tested-platforms>
  <total-usage-count type="integer">0</total-usage-count>
  <updated-at type="datetime">2010-03-03T21:16:26-08:00</updated-at>
  <url>http://github.com/highgroove/scout-plugins/raw/master/memory_profiler/memory_profiler.rb</url>
</plugin-url>
