Skip to content

Instantly share code, notes, and snippets.

Last active September 23, 2020 03:30
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Some scripts for BusyBox to parse out network interface stats and send them to a simple PHP setup for collection & use with Prometheus.
header("Content-Type: text/plain");
$data = file("data.txt");
$bytesRx = $data[0];
$bytesTx = $data[1];
?># TYPE modem_stats_bytesrx counter
modem_stats_bytesrx <?= $bytesRx ?>
# TYPE modem_stats_bytestx counter
modem_stats_bytestx <?= $bytesTx ?>
while true; do curl -k "`cat /sys/class/net/eth0/statistics/rx_bytes | tr -d '\n'`&bytesTx=`cat /sys/class/net/eth0/statistics/tx_bytes | tr -d '\n'`"; sleep 10; done
// Accepts input like:
$bytesTx = intval($_GET['bytesTx']);
$bytesRx = intval($_GET['bytesRx']);
// Display the numbers so the calling instance can see if it's working
print "Got RX: ".number_format($bytesRx)." / Got TX: ".number_format($bytesTx)."\n";
// DANGER: requires the web server user can write to this file.
$fp = fopen("data.txt", "w");
fputs($fp, "$bytesRx\n$bytesTx");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment