Last active
January 24, 2020 23:17
-
-
Save stephenlb/6203514264db57bfbdf3 to your computer and use it in GitHub Desktop.
Network Throughput Bandwidth Rate Consumption Linux Command
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
## =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= | |
## -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- USAGE -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- | |
## | |
## ./network-rate.sh eth0 | |
## | |
## =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= | |
tx_bytes=0 | |
rx_bytes=0 | |
tx_bps=0 | |
rx_bps=0 | |
# update dev delay | |
update() | |
{ | |
delay=$2 | |
cat /proc/net/dev | grep $1 >/tmp/netdev_rate | |
#ts=`date +%s` | |
read dev rb rp re rd ri rf rc rm tb tp te td ti tc ta tc </tmp/netdev_rate | |
#echo $dev $rb $tb | |
if [ $tx_bytes -gt 0 ] ; then | |
tx_b=$(($tb - $tx_bytes)) | |
tx_bps=$(($tx_b / $delay)) | |
tx_mBps=$(($tx_bps / 1048576)) | |
tx_mbps=$(($tx_mBps * 8)) | |
rx_b=$(($rb - $rx_bytes)) | |
rx_bps=$(($rx_b / $delay)) | |
rx_mBps=$(($rx_bps / 1048576)) | |
rx_mbps=$(($rx_mBps * 8)) | |
fi | |
tx_bytes=$tb | |
rx_bytes=$rb | |
} | |
update $1 1 | |
while true | |
do | |
sleep 1 | |
update $1 1 | |
echo "tx $tx_bytes rx $rx_bytes tx MB/s $tx_mBps rx MB/s $rx_mBps" | |
done |
List IP Addresses
All IP public addresses in all regions for all running EC2 instances
REGIONS='us-west-1 us-east-1 ap-south-1 eu-central-1 ap-northeast-1'; for REGION in $REGIONS; do aws ec2 describe-instances --query 'Reservations[*].Instances[*].PublicIpAddress' --output=text --region=$REGION 2>&1 | grep -v python | grep -v Warning; done
#!/bin/bash
## -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
##
## Usage:
## ./resources.sh JUMPSERVER
##
## -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
JUMP="$1"
REGIONS="us-west-1 us-east-1 ap-south-1 eu-central-1 ap-northeast-1"
for REGION in $REGIONS
do CMD="aws ec2 describe-instances --query 'Reservations[*].Instances[*].PublicIpAddress' --output=text --region=$REGION 2>&1 | grep -v python | grep -v Warning"
for IP in `ssh $JUMP "$CMD"`
do echo $IP
ssh $IP "hostname; uptime; free -t | awk 'NR == 2 {print \"RAM Usage: \" \$3/\$2*100 \"%\"}'; awk '{u=\$2+\$4; t=\$2+\$4+\$5; if (NR==1){u1=u; t1=t;} else print \"CPU Usage: \" (\$2+\$4-u1) * 100 / (t-t1) \"%\"; }' <(grep 'cpu ' /proc/stat) <(sleep 1;grep 'cpu ' /proc/stat); curl -sL https://gist.githubusercontent.com/stephenlb/6203514264db57bfbdf3/raw/70eac97a8096c43e7016bc4aae528770fef9a057/network-rate.sh | sudo bash -s eth0 | head -n3"
done
done
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
ssh SERSVER_HOSTNAME "hostname; uptime; free -t | awk 'NR == 2 {print \"RAM Usage: \" \$3/\$2*100 \"%\"}'; awk '{u=\$2+\$4; t=\$2+\$4+\$5; if (NR==1){u1=u; t1=t;} else print \"CPU Usage: \" (\$2+\$4-u1) * 100 / (t-t1) \"%\"; }' <(grep 'cpu ' /proc/stat) <(sleep 1;grep 'cpu ' /proc/stat); curl -sL https://gist.githubusercontent.com/stephenlb/6203514264db57bfbdf3/raw/70eac97a8096c43e7016bc4aae528770fef9a057/network-rate.sh | sudo bash -s eth0 | head -n3"