Module: GreenHat::Memory
- Defined in:
- lib/greenhat/accessors/memory.rb
Overview
Sidekiq Log Helpers
Class Method Summary collapse
- .free ⇒ Object
- .memory_row(mem) ⇒ Object
- .number_to_human_size(num) ⇒ Object
- .percentage(used, total) ⇒ Object
Class Method Details
.free ⇒ Object
4 5 6 |
# File 'lib/greenhat/accessors/memory.rb', line 4 def self.free Thing.where(name: 'free_m') end |
.memory_row(mem) ⇒ Object
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/greenhat/accessors/memory.rb', line 15 def self.memory_row(mem) total = mem.total.to_i total_name = number_to_human_size(total.megabytes) used_name = number_to_human_size(mem.used.to_i.megabytes) = [ '|'.pastel(:green) * percentage(mem.used, total), '|'.pastel(:blue) * percentage(mem.shared, total), '|'.pastel(:cyan) * percentage(mem.buffcache, total), ' ' * percentage(mem.free, total) ].join # Make Even padding = 125 - .unpastel.size += ' ' * padding if padding.positive? [ mem.kind.ljust(4).pastel(:cyan), ' ['.pastel(:bright_black), .ljust(120), used_name.pastel(:magenta), ' / '.pastel(:bright_black), total_name.pastel(:blue), ']'.pastel(:bright_black) ].join end |
.number_to_human_size(num) ⇒ Object
42 43 44 |
# File 'lib/greenhat/accessors/memory.rb', line 42 def self.number_to_human_size(num) ActiveSupport::NumberHelper.number_to_human_size num end |
.percentage(used, total) ⇒ Object
8 9 10 11 12 13 |
# File 'lib/greenhat/accessors/memory.rb', line 8 def self.percentage(used, total) return 0 if used.to_i.zero? # Show at least one bar if below 1% [1, ((used.to_i / total.to_f).round(1) * 100).round].max end |