Debian Codegraph @

vicious/widgets/uptime_freebsd.lua

raw symbols SCIP
1 -- uptime widget type for FreeBSD
2 -- Copyright (C) 2017,2019 mutlusun <[email protected]>
3 -- Copyright (C) 2019 Nguyễn Gia Phong <[email protected]m>
4 --
5 -- This file is part of Vicious.
6 --
7 -- Vicious is free software: you can redistribute it and/or modify
8 -- it under the terms of the GNU General Public License as
9 -- published by the Free Software Foundation, either version 2 of the
10 -- License, or (at your option) any later version.
11 --
12 -- Vicious is distributed in the hope that it will be useful,
13 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
14 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 -- GNU General Public License for more details.
16 --
17 -- You should have received a copy of the GNU General Public License
18 -- along with Vicious. If not, see <https://www.gnu.org/licenses/>.
19
20 -- {{{ Grab environment
21 local tonumber = tonumber
22 local math = { floor = math.floor }
23 local os = { time = os.time }
24
25 local helpers = require("vicious.helpers")
26 -- }}}
27
28 -- Uptime: provides system uptime and load information
29 -- vicious.widgets.uptime
30 local uptime_freebsd = {}
31
32 -- {{{ Uptime widget type
33 function uptime_freebsd.async(format, warg, callback)
34 helpers.sysctl_async(
35 { "vm.loadavg", "kern.boottime" },
36 function(ret)
37 local l1, l5, l15 = ret["vm.loadavg"]:match(
38 "{ ([%d]+%.[%d]+) ([%d]+%.[%d]+) ([%d]+%.[%d]+) }")
39 local up_t = os.time() - tonumber(
40 ret["kern.boottime"]:match"sec = ([%d]+)")
41
42 -- Get system uptime
43 local up_d = math.floor(up_t / (3600 * 24))
44 local up_h = math.floor((up_t % (3600 * 24)) / 3600)
45 local up_m = math.floor(((up_t % (3600 * 24)) % 3600) / 60)
46
47 return callback({ up_d, up_h, up_m, l1, l5, l15 })
48 end)
49 end
50 -- }}}
51
52 return helpers.setasyncall(uptime_freebsd)