]> git.madduck.net Git - etc/awesome.git/blob - widgets/sysload.lua

madduck's git repository

Every one of the projects in this repository is available at the canonical URL git://git.madduck.net/madduck/pub/<projectpath> — see each project's metadata for the exact URL.

All patches and comments are welcome. Please squash your changes to logical commits before using git-format-patch and git-send-email to patches@git.madduck.net. If you'd read over the Git project's submission guidelines and adhered to them, I'd be especially grateful.

SSH access, as well as push access can be individually arranged.

If you use my repositories frequently, consider adding the following snippet to ~/.gitconfig and using the third clone URL listed for each project:

[url "git://git.madduck.net/madduck/"]
  insteadOf = madduck:

148319dd22c5f84b71a6ac58d4e0f65c04bc7bc8
[etc/awesome.git] / widgets / sysload.lua
1
2 --[[
3                                                   
4      Licensed under GNU General Public License v2 
5       * (c) 2013,      Luke Bonham                
6       * (c) 2010-2012, Peter Hofmann              
7                                                   
8 --]]
9
10 local helpers      = require("lain.helpers")
11 local wibox        = require("wibox")
12 local io           = { open = io.open }
13 local string       = { match  = string.match }
14 local setmetatable = setmetatable
15
16 -- System load
17 -- lain.widgets.sysload
18 local sysload = helpers.make_widget_textbox()
19
20 local function worker(args)
21     local args     = args or {}
22     local timeout  = args.timeout or 2
23     local settings = args.settings or function() end
24
25     function update()
26         local f = io.open("/proc/loadavg")
27         local ret = f:read("*all")
28         f:close()
29
30         load_1, load_5, load_15 = string.match(ret, "([^%s]+) ([^%s]+) ([^%s]+)")
31
32         widget = sysload.widget
33         settings()
34     end
35
36     helpers.newtimer("sysload", timeout, update)
37
38     return sysload
39 end
40
41 return setmetatable(sysload, { __call = function(_, ...) return worker(...) end })