Active RAM

From awesome
Jump to: navigation, search

IceBrain's Active RAM Widget

This function returns the Active memory usage, according to /proc/meminfo. It is a "light" function as it doesn't spawn any processes and it's composed of plain Lua, so it should work on all Awesome versions.

Function code

Paste this inside your rc.lua:

There are two versions, copy only one, according to your taste. The first prints the usage in MB:

 function activeram()
     local active
     for line in io.lines('/proc/meminfo') do
         for key, value in string.gmatch(line, "(%w+):\ +(%d+).+") do
             if key == "Active" then active = tonumber(value) end
         end
     end
      
     return string.format("%.2fMB",(active/1024))
 end

This prints in percentage of total RAM used:

 function activeram()
 	local active, total
 	for line in io.lines('/proc/meminfo') do
 		for key, value in string.gmatch(line, "(%w+):\ +(%d+).+") do
 			if key == "Active" then active = tonumber(value)
 			elseif key == "MemTotal" then total = tonumber(value) end
 		end
 	end
 	
 	return string.format("%.0f%%",(active/total)*100)
 end

Usage

Now, you can use a normal textbox to show you RAM usage:

First, create the widget:

 meminfo = widget({ type = "textbox", align = "right" })

Then, assign a hook to update it:

 awful.hooks.timer.register(10, function() meminfo.text = activeram() end)

Finally, assign it to your wibox:

 mywibox[s].widgets = {   ...
                          meminfo,
                          ...
                          s == 1 and mysystray or nil }
Personal tools