Class: MemoryUsage
- Inherits:
-
JsonTail::Parser
- Object
- JsonTail::Parser
- MemoryUsage
- Defined in:
- lib/json_tail/parsers/memory_usage.rb
Overview
cada parser debiera tener un método parse() y otro build_report() que devuelva un objecto de clase Hash para que sea transformado a JSON después.
Class Method Summary collapse
Methods inherited from JsonTail::Parser
Class Method Details
.build_report(options) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/json_tail/parsers/memory_usage.rb', line 9 def build_report() content = {} total_mem = `free | grep Mem: | awk '{print $2}'`.chomp total_mem_used = `free | grep buffers/cache: | awk '{print $3}'`.chomp total_mem_avai = `free | grep Mem: | awk '{print $4}'`.chomp res_swap_info = `free | grep Swap:`.split total_swap = res_swap_info[1] per_swap_used = (res_swap_info[2].to_i*100)/total_swap.to_i # percentage per_swap_avai = (res_swap_info[3].to_i*100)/total_swap.to_i # percentage content = { "total_mem" => total_mem, "total_mem_used" => total_mem_used, "total_mem_avai" => total_mem_avai, "total_swap" => total_swap, "total_swap_used" => total_swap_used, "total_swap_avai" => total_swap_avai } report(['parser'], content) end |