Binary Nature where the analog and digital bits of nature connect

  • Subscribe to our RSS feed.
  • Twitter
  • StumbleUpon
  • Reddit
  • Facebook
  • Digg

Monday, 18 March 2013

Measure Internet Connection Speed from the Linux Command Line

Posted on 21:03 by Unknown
This is a sample solution of how to test the Internet connection speed for an Amazon Web Services (AWS) EC2 Linux instance from the command line. After a little research and testing, I decided to choose the speedtest-cli tool by Matt Martz for my solution. One of the primary reasons for choosing this tool was because it interfaces with the popular Speedtest.net site.

Connect to AWS EC2 VM Instance
Our first task is to connect to our EC2 VM instance via SSH. I am using the Amazon Linux AMI 2012.09.1 image. I will also be using the default ec2-user user for my scenario. If connecting from a Windows client, refer to the the Amazon AWS documentation as I will be using the Mac/Linux method with the ssh tool. I have my AWS RSA private key file stored within a hidden directory in my $HOME directory, so I will use the following command to connect to my EC2 Linux instance:
$ ssh -i ~/.aws/awskey.pem ec2-user@ec2-x-x-x-x.compute-1.amazonaws.com

Verify Python Version
The speedtest-cli tool is developed with the Python programming language. The README file states speedtest-cli is written for Python 2.4 thru 3.3. Let's verify our Python version by runnning the following command:
$ python -V
Python 2.6.8

Download and Install Git
The Amazon Linux AMI is a RPM-based distribution, so we will be using YUM for package management. Since the speedtest-cli tool is hosted at GitHub, we will make it simple by fetching the tool with Git. The git package is available from the default amzn-main repo. Run the following command:
$ sudo yum -y install git

Create Directory for Repo
We will now create the directory path to contain the speedtest-cli repo directory and then navigate into it. Run the following from the command line:
$ mkdir -p ~/repo/remote; cd $_

Clone the Repo
Let's now clone the remote repository into a newly created local directory. Run the following command:
$ git clone https://github.com/sivel/speedtest-cli.git

Copy/Install Tool
We now have a choice of where to copy the tool for scope of use. We can either elect to have the tool available for only our current user and/or system-wide. I've included examples for both.

# Current User
If we check our $PATH variable, we notice there is a reference to a bin directory within our home directory.
$ echo $PATH
/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/opt/aws/bin:/home/ec2-user/bin

Even though the private bin directory is defined in our $PATH variable, we still need to create it before use. Run the following commands to create the private bin directory and copy the speedtest-cli tool to it:
$ mkdir ~/bin
$ cp ~/repo/remote/speedtest-cli/speedtest_cli.py ~/bin/speedtest-cli

# System
Alternatively, we can make the tool available for all interactive users on the system. Run the following command:
$ sudo cp ~/repo/remote/speedtest-cli/speedtest_cli.py /usr/local/bin/speedtest-cli

Usage
By running the tool with no options, the speedtest-cli tool will select a Speedtest.net host nearest to your server's location to conduct the Internet connection performance test. We can change the default behavior of the tool by running it with different options.

My EC2 VM instance is physically hosted in the US East (Northern Virginia) Region, and I would like to determine what kind of network performance it will achieve when it utilizes one of the Speedtest.net hosts back here in Seattle, WA. The following command will display a list of Speedtest.net servers sorted by distance and filtered by the seattle string.
$ speedtest-cli --list | grep -i seattle
1074) Towerstream (Seattle, WA, United States) [3694.99 km]
2523) Wowrack.com (Seattle, WA, United States) [3694.99 km]
1423) Condointernet.net (Seattle, WA, United States) [3694.99 km]
2965) FiberCloud, Inc (Seattle, WA, United States) [3694.99 km]

I'm interested in the FiberCloud, Inc host for my target, so I will apply the server ID number to the server parameter value. I would also like to generate a graphical image of my test run result with the share option. Run the following command:
$ speedtest-cli --server 2965 --share
Retrieving speedtest.net configuration...
Retrieving speedtest.net server list...
Testing from Amazon.com (x.x.x.x)...
Hosted by FiberCloud, Inc (Seattle, WA) [3694.99 km]: 61.671 ms
Testing download speed........................................
Download: 88.94 Mbit/s
Testing upload speed..................................................
Upload: 30.14 Mbit/s
Share results: http://www.speedtest.net/result/2583822707.png
# Multiple Servers
Let's take this a step further and test our Internet connection performance against multiple servers spanning across the globe in a single batch.

For example, I would like to test against servers in Chicago, London, and Tokyo. Our first task is filter the server list to these specific locations. Run the following command:

$ speedtest-cli --list | grep -iE 'chicago|london|tokyo'
1071) Towerstream (Chicago, IL, United States) [914.11 km]
3084) SilverIP Communications (Chicago, IL, United States) [914.11 km]
1776) Comcast (Chicago, IL, United States) [914.11 km]
2574) ServerCentral (Chicago, IL, United States) [914.11 km]
958) FastSoft (Chicago, IL, United States) [915.13 km]
2153) CONNEXIONS4LONDON Ltd (Bournemouth, Great Britain) [5828.93 km]
226) Structured Communications (London, Great Britain) [5918.34 km]
385) Namesco (London, Great Britain) [5918.34 km]
3047) FidoNet (London, Great Britain) [5918.34 km]
2789) Vodafone UK (London, Great Britain) [5918.34 km]
251) World's Fastest Indian (Tokyo, Japan) [10868.84 km]
2725) Alocac, Inc. (Tokyo, Japan) [10870.93 km]

I've identified a server to test against for each location. Our next task is to insert the server ID as keys mapped to location string values (ex. [2965]="Seattle") in an associative array data type.

Note: Associative arrays were introduced in Bash version 4. Let's verify our Bash meets this requirement. Run the following command:

$ echo $BASH_VERSION
4.1.2(1)-release

We are good to go, so let's move on to creating the associative array and implementing a for loop for iteration. Run the following commands:

$ declare -A servers=( [2574]="Chicago" [2789]="London" [251]="Tokyo" )
$ for server in ${!servers[@]}; do echo "Location: ${servers[$server]}"; speedtest-cli --server $server --simple; echo; done
Location: Tokyo
Ping: 73.989 ms
Download: 31.37 Mbit/s
Upload: 3.93 Mbit/s

Location: London
Ping: 67.631 ms
Download: 68.65 Mbit/s
Upload: 22.39 Mbit/s

Location: Chicago
Ping: 64.055 ms
Download: 39.73 Mbit/s
Upload: 60.35 Mbit/s

Email ThisBlogThis!Share to XShare to FacebookShare to Pinterest
Posted in AWS, Linux, SSH | No comments
Newer Post Older Post Home

0 comments:

Post a Comment

Subscribe to: Post Comments (Atom)

Popular Posts

  • Cisco ASA SSL VPN with Active Directory
    There is little doubt the bring-your-own-device (BYOD) strategy is becoming a popular method to access company resources. As technical prof...
  • PowerShell Function for Windows System Memory Statistics
    Memory is one of the four primary hardware resources an operating system manages. The other three are cpu, disk, and network. Analysis of sy...
  • Integrate VMware Fusion with GNS3 on your Mac
    At long last, we can finally integrate VMware Fusion with GNS3. VMware Workstation for Windows and Linux has had this capability for quite s...
  • Configure Inter-VLAN routing on a Cisco L3 Catalyst Switch
    I recently had to configure inter-VLAN routing at a client's site. I don't have to perform this task on a regular basis, so I figur...
  • SSL VPN configuration on Cisco ASA with AnyConnect VPN client
    This post will describe how to setup a Cisco Adaptive Security Appliance (ASA) device to perform remote access SSL VPN with the stand-alone ...
  • Enable sudo for RHEL and CentOS
    Sudo is an arguably safer alternative to logging in (or using the su command) to the root account. Sudo allows you to partition and delegat...
  • Get Exchange Server Version and Update Info with PowerShell
    I prefer not to "reinvent the wheel", so I spent quite a bit of time searching the web for available code that would perform the t...
  • Cisco Security Device Manager on the Mac
    Cisco Router and Security Device Manager (SDM) is a Web-based device-management tool that enables you to deploy and manage the services on a...
  • Install Request Tracker 4 on Ubuntu Server
    The CentOS6/RT4 blog post has generated terrific feedback, so I figure an Ubuntu (and Debian) distribution port is essential. The core com...
  • Install Request Tracker 4
    The argument could be made Request Tracker is the de facto standard when it comes to issue tracking systems. Maybe the only drawback of RT ...

Categories

  • AD
  • Apache
  • AWS
  • Cisco
  • Exchange
  • FFmpeg
  • GNS3
  • Linux
  • Mac
  • MariaDB
  • MySQL
  • PowerShell
  • RT
  • Security
  • SSH
  • VMware
  • Windows
  • Zenoss

Blog Archive

  • ▼  2013 (8)
    • ►  October (1)
    • ►  September (1)
    • ►  August (1)
    • ►  May (1)
    • ►  April (1)
    • ▼  March (1)
      • Measure Internet Connection Speed from the Linux C...
    • ►  February (1)
    • ►  January (1)
  • ►  2012 (3)
    • ►  December (1)
    • ►  November (1)
    • ►  April (1)
  • ►  2011 (3)
    • ►  June (1)
    • ►  May (2)
  • ►  2010 (8)
    • ►  August (1)
    • ►  July (1)
    • ►  June (1)
    • ►  May (1)
    • ►  April (1)
    • ►  March (1)
    • ►  February (1)
    • ►  January (1)
  • ►  2009 (3)
    • ►  December (1)
    • ►  November (1)
    • ►  October (1)
Powered by Blogger.

About Me

Unknown
View my complete profile