Anand Sudhanaboina

Network Performance Analysis Using CURL

curl can be handy tool to perform network analysis.

1
curl -o /dev/null  -s -w "%{time_total}" http://anands.github.io

This will print the total time in seconds that the full operation lasted.

Used flags in this command:

  1. -o: This is used to write output to specified destination, as we are focused on just performance we are writing to /dev/null so the stdout of curl will be ignored.

  2. -s: Meant for silent, this will skip the debug table (in which you can see some stats as well).

  3. -w: This commad defines what to display on stdout after a completed and successful operation. The desired output can be formatted using file or in-inline.

You can see entire curl doc (supported variables, etc) for -w flag here

Custom formatting:

We can feed in the desired format using a file or in-inline, in-inline examples:

1
2
curl -o /dev/null  -s -w "%{time_total}" http://anands.github.io
curl -o /dev/null  -s -w "Total Time: %{time_total}\nDownload Speed: %{speed_download}" http://anands.github.io

To read from a particular file you need to specify it as “@filename”, example:

1
curl -w "@format.txt" -o /dev/null -s http://anands.github.io/

I used this to log the info in json format, and here’s how my format.txt looks like:

1
2
3
4
5
6
7
8
9
10
11
12
{
  "http_code" : "%{http_code}",
  "num_connects" : "%{num_connects}",
  "remote_ip" : "%{remote_ip}",
  "remote_port" : "%{remote_port}",
  "size_download" : "%{size_download}",
  "size_header" : "%{size_header}",
  "time_connect" : "%{time_connect}",
  "time_pretransfer" : "%{time_pretransfer}",
  "time_starttransfer" : "%{time_starttransfer}",
  "time_total" : "%{time_total}"
}

Sample output:

1
2
3
4
5
6
7
8
9
10
11
12
13
curl -w "@format.json" -o /dev/null -s http://anands.github.io/ | python -m json.tool
{
    "http_code": "200",
    "num_connects": "1",
    "remote_ip": "192.30.252.154",
    "remote_port": "80",
    "size_download": "7876",
    "size_header": "358",
    "time_connect": "0.032",
    "time_pretransfer": "0.032",
    "time_starttransfer": "1.113",
    "time_total": "1.119"
}

For constant monitoring, create a cron job which runs this command every minute and push data to desired systems.

Comments