1 -- Authors: Relu Patrascu <ikoflexer@gmail.com>
2 -- License: LGPL, version 2.1 or later
3 -- Last Changed: 2004-11-05
7 -- Copyright (c) Relu Patrascu 2004.
9 -- Ion is free software; you can redistribute it and/or modify it under
10 -- the terms of the GNU Lesser General Public License as published by
11 -- the Free Software Foundation; either version 2.1 of the License, or
12 -- (at your option) any later version.
16 -- Neither am I a lua expert nor do I have the time to invest in writing
17 -- better code here. I simply needed this utility and it works OK for me.
18 -- I give no guarantees of any kind for this code. Suggestions for
19 -- improvement are welcome.
20 -- ikoflexer at gmail dot com
22 if not statusd_iface
then
23 statusd_iface
={ interval
=10*1000 }
27 local function get_iface_proc()
29 local f
=io
.open('/proc/net/wireless', 'r')
33 -- first 2 lines -- headers
36 -- the third line has wifi info
39 f
=io
.open('/proc/net/dev', 'r')
43 -- first 2 lines -- headers, next line check for lo
47 st
, en
, iface
= string.find(s
, '(%w+:)')
48 if iface
== 'lo:' then
54 st
, en
, iface
= string.find(s
, '(%w+:)')
56 return tostring(iface
)
58 st
, en
, iface
= string.find(s
, '(%w+:)')
60 return tostring(iface
)
63 local function get_iface_fn()
67 local get_iface
, iface_timer
69 local function update_iface()
70 statusd
.inform("iface", get_iface())
71 iface_timer
:set(statusd_iface
.interval
, update_iface
)
75 get_iface
=get_iface_fn()
76 iface_timer
=statusd
.create_timer()