~ubuntuone-support/+junk/syncdaemon-perftest

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/bin/bash

# global configuration
# Variables used:
#   STATSD_PREFIX
#   STATSD_HOST
#   STATSD_PORT
# See syncdaemon-perftest.conf-example for example
source $(dirname $0)/perftest.conf

# credentials
# updown-test.creds is in the format that ubuntuone-sso-login creates when ran
# with "--format shell" option
source $(dirname $0)/updown-test.creds

REMOTE_TEST_FILE_CONTENT_URL=https://files.one.ubuntu.com/content/~/Ubuntu%20One/updown-test.bin
LOCAL_TEST_FILE=/tmp/updown-test.bin

CURL_ARGS="-s"

# 10 Mb
dd if=/dev/urandom of="$LOCAL_TEST_FILE" bs=1024 count=10240 2>/dev/null

# Upload
UPLOAD_SPEED=$(curl $CURL_ARGS -H "Content-Type: application/octet-stream" \
     -T "$LOCAL_TEST_FILE" \
     -w '%{speed_upload}\n' \
     -o /dev/null \
     $(oauth-sign -m PUT -f url "$REMOTE_TEST_FILE_CONTENT_URL"))

# Download
DOWNLOAD_SPEED=$(curl $CURL_ARGS -H "Cache-Control: no-cache, must-revalidate" \
     -w '%{speed_download}\n'\
     -o /dev/null \
     $(oauth-sign -f url "$REMOTE_TEST_FILE_CONTENT_URL"))

UPLOAD_SPEED=$(awk "BEGIN{ print int($UPLOAD_SPEED) }")
DOWNLOAD_SPEED=$(awk "BEGIN{ print int($DOWNLOAD_SPEED) }")

DATE=`date +%s`

echo "$STATSD_PREFIX.updown.upload_speed:$UPLOAD_SPEED|g" | \
	nc -w 0 -v -u $STATSD_HOST $STATSD_PORT
echo "$STATSD_PREFIX.updown.download_speed:$DOWNLOAD_SPEED|g" | \
	nc -w 0 -v -u $STATSD_HOST $STATSD_PORT

# cleanup

curl $CURL_ARGS -X DELETE `oauth-sign -m DELETE -f url "$REMOTE_TEST_FILE_CONTENT_URL"`
rm "$LOCAL_TEST_FILE"