Skip to content

Instantly share code, notes, and snippets.

@riccardobl
Last active April 6, 2022 23:47
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save riccardobl/80445ec5e2eb441ce0b8 to your computer and use it in GitHub Desktop.
Save riccardobl/80445ec5e2eb441ce0b8 to your computer and use it in GitHub Desktop.
Moved to https://github.com/riccardobl/simple-bash-bandwidth-monitor
# Moved to https://github.com/riccardobl/simple-bash-bandwidth-monitor
${font sans-serif:bold:size=8}SERVERS ${hr 2}
${font sans-serif:normal:size=8}IP address: $alignr XXXXXXXXXXXXXXXXXX
DLS: ${texeci 5 curl --silent "http://XXXXXXXXXXXXXXXXXX/status.php?t=down&f=HUMAN"} $alignr total: ${texeci 5 curl --silent "http://XXXXXXXXXXXXXXXXXX/status.php?t=total-down&f=HUMAN"}
ULS: ${texeci 5 curl --silent "http://XXXXXXXXXXXXXXXXXX/status.php?t=up&f=HUMAN"} $alignr total: ${texeci 5 curl --silent "http://XXXXXXXXXXXXXXXXXX/status.php?t=total-up&f=HUMAN"}
<?php
// Moved to https://github.com/riccardobl/simple-bash-bandwidth-monitor
$type=@$_REQUEST['t'];
if( $type!=="down" && $type!=="total-down" && $type!=="total-up" ) $type="up";
$format=@$_REQUEST['f'];
if( $format !== "HUMAN" && $format!=="GB" && $format!=="MB" && $format!=="KB" ) $format="B";
echo exec("./status.sh $type eth0 $format");
?>
#!/bin/bash
# Moved to https://github.com/riccardobl/simple-bash-bandwidth-monitor
type=$1;
interface=$2
out_format=$3
data=($(grep $interface /proc/net/dev))
sleep 2
data2=($(grep $interface /proc/net/dev))
if [[ "$type" == *"up"* ]]
then
id=9
else
id=1
fi
sa=${data2[$id]}
if [[ "$type" == *"total"* ]]
then
sb=0
else
sb=${data[$id]}
fi
delta=$(( sa - sb ))
if [ "$out_format" == "HUMAN" ]
then
numfmt --to=iec-i --suffix=B $delta
elif [ "$out_format" == "GB" ]
then
echo $delta | awk '{printf "%.2f", $1 / 1024 / 1024 / 1024}'
elif [ "$out_format" == "MB" ]
then
echo $delta | awk '{printf "%.2f", $1 / 1024 / 1024}'
elif [ "$out_format" == "KB" ]
then
echo $delta | awk '{printf "%.2f", $1 / 1024}'
else
echo $delta
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment