Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Branch: master
Fetching contributors…

Cannot retrieve contributors at this time

executable file 63 lines (48 sloc) 1.253 kB
#!/usr/bin/lua
-- xstat v0.02
-- reports total amount of sent/recieved traffic in megabytes.
local app = "xstat";
local version = 0.02;
function printf(s,...)
return io.write(s:format(...))
end
function mb(bytes)
return (bytes / 1024) / 1024;
end
function get_stats()
local tx_file = "/sys/class/net/eth0/statistics/tx_bytes";
local rx_file = "/sys/class/net/eth0/statistics/rx_bytes";
io.input(tx_file);
local tx_mb = mb( io.read("*line") );
io.input(rx_file);
local rx_mb = mb( io.read("*line") );
return tx_mb, rx_mb;
end
function to_tty(s, r)
printf("%8s: %4d MB\n%s: %4d MB\n",
"Sent", s,
"Recieved", r
);
end
function to_dzen(s, r)
local dzen_fg = "^fg(#888888)";
local dzen_tx_c = "^fg(#ff0000)";
local dzen_rx_c = "^fg(#ffff00)";
printf("%s %s%s: %4d MB | %s %s%s: %4d MB\n",
dzen_rx_c, "Recieved", dzen_fg, r,
dzen_tx_c, "Sent", dzen_fg, s
);
end
function usage(app, ver)
printf("%s v%.2f\n\nUsage: %s [-t -d -h]\n", app, ver, app);
end
local sent, recieved = get_stats();
if(arg[1] == '-d') then
to_dzen(sent, recieved);
elseif(arg[1] == '-t') then
to_tty(sent, recieved);
elseif(arg[1] == '-h') then
usage(app, version);
else
to_tty(sent, recieved);
end
Jump to Line
Something went wrong with that request. Please try again.