Class: Nephelae::MemUsage
- Defined in:
- lib/nephelae/plugins/mem_usage.rb
Instance Attribute Summary
Attributes inherited from Plugin
Instance Method Summary collapse
Methods inherited from Plugin
Constructor Details
This class inherits a constructor from Nephelae::Plugin
Instance Method Details
#get_metrics ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/nephelae/plugins/mem_usage.rb', line 5 def get_metrics metrics = Metrics.new(namespace) output = `#{command}` if $?.success? stats = parse_status(output) mem_total = stats[:mem_total] metrics.append_metric('MemoryTotal', mem_total, {unit: 'Kilobytes'}) mem_free = stats[:mem_free] + stats[:buffers] + stats[:cached] metrics.append_metric('MemoryFree', mem_free, {unit: 'Kilobytes'}) mem_used = stats[:mem_total] - mem_free metrics.append_metric('MemoryUsed', mem_used, {unit: 'Kilobytes'}) unless mem_total == 0 mem_used_percent = (mem_used.to_f / mem_total.to_f * 100).to_i metrics.append_metric('MemoryUsedPercentage', mem_used_percent, {unit: 'Percent'}) end metrics.append_metric('SwapTotal', stats[:swap_total], {unit: 'Kilobytes'}) metrics.append_metric('SwapFree', stats[:swap_free], {unit: 'Kilobytes'}) swap_used = stats[:swap_total] - stats[:swap_free] metrics.append_metric('SwapUsed', swap_used, {unit: 'Kilobytes'}) unless stats[:swap_total] == 0 swap_used_percent = (swap_used.to_f / stats[:swap_total].to_f * 100).to_i metrics.append_metric('SwapUsedPercentage', swap_used_percent, {unit: 'Percent'}) end end return metrics end |