]> git.madduck.net Git - etc/awesome.git/blob - widget/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:

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