Skip to content

Instantly share code, notes, and snippets.

@aa65535
Created November 29, 2014 12:15
Show Gist options
  • Save aa65535/ae6581c08768860700dc to your computer and use it in GitHub Desktop.
Save aa65535/ae6581c08768860700dc to your computer and use it in GitHub Desktop.
rpi systatus scrip
#!/bin/bash
DELAY=5
PID_FILE=/tmp/systatus.pid
OUT_FILE=/tmp/systatus.json
RX_FILE=/sys/class/net/eth0/statistics/rx_bytes
TX_FILE=/sys/class/net/eth0/statistics/tx_bytes
TEMP_FILE=/sys/class/thermal/thermal_zone0/temp
if [ "stop" = "$1" ]; then
[ -f $PID_FILE ] && kill -9 $(cat $PID_FILE)
exit 0
fi
(while [ 1 ]; do
rx0=$(cat $RX_FILE)
tx0=$(cat $TX_FILE)
sleep $DELAY
rx1=$(cat $RX_FILE)
tx1=$(cat $TX_FILE)
if [ $rx0 -gt $rx1 ]; then
rx1=$(($rx1 + 4294967295))
fi
if [ $tx0 -gt $tx1 ]; then
tx1=$(($tx1 + 4294967295))
fi
mem=$(free | awk '/cache:/ {print $3/1024}')
load=$(awk '{print $1}' /proc/loadavg)
temp=$(awk '{print $1/1000}' $TEMP_FILE)
# $1 $2 $3 $4 $5 $6 $7 $8
echo $DELAY $rx0 $rx1 $tx0 $tx1 $mem $load $temp | \
awk '{printf("{\"rx\": %.2f, \"tx\": %.2f, \"mem\": %.2f, \"load\": %.2f, \"temp\": %.2f}",($3-$2)/1024/$1,($5-$4)/1024/$1,$6,$7,$8)}' >$OUT_FILE
done) >/dev/null 2>&1 &
echo $! >$PID_FILE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment