class Widgets::Memory
The Memory widget reads /proc/meminfo.
By default the widget displays a precentage like: “memory: #{percentage}%”
You can make use of the instances values: @total, @available, @free, @cached and @meminfo. The values are in KB. @meminfo is a hash containing the raw /proc/meminfo data.
Example:
widget :memory do "cache: #{@cached / 1_000_000}GB" end
Public Class Methods
Source
# File src/widgets/memory.rb, line 17 def initialize options super @label = Gtk::Label.new '' init_timer append @label end
Calls superclass method
Widgets::BaseWidget::new
Public Instance Methods
Source
# File src/widgets/memory.rb, line 23 def update @meminfo = File.read('/proc/meminfo').lines.map { key, value = it.match(/^([^:\s]+): +(\d+)/).captures [key, value.to_i] }.to_h @total = @meminfo['MemTotal'] @available = @meminfo['MemAvailable'] @free = @meminfo['MemFree'] @cached = @meminfo['Cached'] percentage_used = ((@total - @available) / @total.to_f) * 100 @label.set_text instance_exec(&@proc) || "memory: #{percentage_used.round(0)}%" end