Created
December 12, 2014 07:57
-
-
Save OnkelTem/ea6d66b8ad1f3dc6993f to your computer and use it in GitHub Desktop.
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 | |
[[ -n $args ]] || info "Use params to set number of MBytes to transmit, default 100. e.g.: $current_task=50" | |
IFS=',' read -a params <<< "$args" | |
local mb="${params[0]:-100}" | |
local iperf_port=5001 | |
# Kill possible failed iperf | |
rcmd root "for pid in \$(pidof iperf); do kill -9 \$pid; done" | |
rcmd root "nohup iperf -s -D -p$iperf_port > /dev/null 2>&1 &" 1 0 "Starting up iperf daemon" | |
info "Running test (downloading ${mb} MBytes of data)..." | |
iperf "-p$iperf_port" -c "$R_HOST" -i 2 -n ${mb}M | |
rcmd root "for pid in \$(pidof iperf); do kill -9 \$pid; done" 1 0 "Stopping iperf daemon" |
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 | |
[[ -n $args ]] || info "Use params to set transfer size in Mb, e.g.: test=10 for 10Mb" | |
IFS=',' read -a params <<< "$args" | |
size="${params[0]}" | |
random=$[ 1 + $[ RANDOM % 1000 ]] | |
local test_dir="$R_DEPLOY_ROOT/${R_DEPLOY_DIRS[0]}/speedtest$random" | |
test_host=$(basename $test_dir) | |
dbg test_dir=$test_dir | |
local method="urandom" | |
info "Generating $method.bin file..." | |
rcmd $R_USER "mkdir -p $test_dir/www && cd $test_dir/www && dd if=/dev/$method of=$method.bin bs=1MB count=$size" || exit 1 | |
# Apply acl | |
mkdir -p "$tmp_dir/$current_task" | |
declare -A acl_vars | |
acl_vars[USER]="$R_USER" | |
acl_vars[WWW_USER]="$R_WWW_USER" | |
m11 "$(declare -p acl_vars)" "acl.conf" > "$tmp_dir/$current_task/acl.conf" | |
. $AWSCONF_DIR/includes/acl || exit 1 | |
acl_target="remote" | |
acl_reset "$test_dir" | |
acl_apply "$test_dir" "$tmp_dir/$current_task/acl.conf" | |
test_host=$(basename $test_dir) | |
echo $(dnsip "$R_HOST") "$test_host" > "$tmp_dir/hosts" | |
info "Running test (downloading $method.bin [${size}MB])..." | |
speed=$( | |
sudo unshare --mount -- /bin/bash -c "mount --make-rprivate / && mount --bind $tmp_dir/hosts /etc/hosts && sudo -u $USER curl -s -w 'scale=0; %{speed_download}/1\n' http://$test_host/$method.bin -o /dev/null" | bc | |
) | |
bits=$(( speed * 8 )) | |
suffixes=( '' Kbits Mbits Gbits Tbits ) | |
s=0 | |
while (( bits / 1000 / 1000 )); do | |
(( ++s, bits/=1000 )) | |
done | |
info "Speed: $bits ${suffixes[s]}/sec" | |
# Cleaning up | |
rcmd $R_USER "rm -rf $test_dir" 1 0 "Cleanup." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment