Http/https Monitoring Get response time (DNS resolution time, RRT time, server processing time, etc.)

Source: Internet
Author: User
Tags local time remote ftp server

Sometimes in order to test the network situation, you need to return to each phase of time, such as time-consuming DNS resolution, to establish a connection to the time spent, from the establishment of the connection to prepare the transfer of the use of the Times, from the establishment of the connection to the start of the transfer time, the entire process, the amount of data downloaded, download speed, Upload speed, etc.

Sometimes in order to test the network situation, you need to return to each phase of time, such as time-consuming DNS resolution, to establish a connection to the time spent, from the establishment of the connection to prepare the transfer of the use of the Times, from the establishment of the connection to the start of the transfer time, the entire process, the amount of data downloaded, download speed, Upload speed and so on. The following script obtains the above information:

Curl information see: http://curl.haxx.se/libcurl/c/curl_easy_getinfo.html

Copy CodeThe code is as follows:
###################################
# # # author:www.ttlsa.com # #
# # QQ Group: 39514058 # # #
# # e-mail: [email protected] # # #
###################################
Use strict;
Use Data::D umper;
Use Www::curl::easy;

if ([email protected]) {
 print "usaging: $ url\n";
 print "For example: $ www.ttlsa.com\n";
 exit;
}

My $curl = new Www::curl::easy;
Open My $response _body, ">/dev/null";
$curl->setopt (curlopt_header,1);
$curl->setopt (curlopt_url, $ARGV [0]);
$curl->setopt (curlopt_writedata,\ $response _body);
$curl->perform;
My $err = $curl->errbuf;
if (! $err) {
 my $st = &gettime;
 my $http _code = $curl->getinfo (curlinfo_response_code);
 my $http _dns_time = $curl->getinfo (curlinfo_namelookup_time);
 my $http _conn_time = $curl->getinfo (curlinfo_connect_time);
  #my $http _app_time = $curl->getinfo (curlinfo_appconnect_time);
 my $http _pre_tran_time = $curl->getinfo (curlinfo_pretransfer_time);
 my $http _start_tran_time = $curl->getinfo (curlinfo_starttransfer_time);
 my $http _total_time = $curl->getinfo (curlinfo_total_time);
 my $http _size_down = $curl->getinfo (curlinfo_size_download);
 my $http _speed_down = $curl->getinfo (curlinfo_speed_download);

printf "Local_time:%s, Http_code:%d, dns_time:%.3fms, Conn_time:%.3fms, Pre_tran_time:%.3fms, Start_tran_time:%.3FMS , Total_time:%.3fms, Size_download:%db, Speed_download:%db/s ", ($st, $http _code, $http _dns_time, $http _conn_time,$ Http_pre_tran_time, $http _start_tran_time, $http _total_time, $http _size_down, $http _speed_down);
Write

Format stdout_top=
All kinds of response time details of the site [email protected]| |
$%
=========================
+---------------------+------+-------------+--------------+--------------------------+------------------------+ -------------+-----------+------------+
| local time | Status | DNS Resolution Time | Establish Connection Time | From establishing a connection to preparing the transfer time | From establishing a connection to starting transfer time | Entire Process Time | Download Data volume | Average download speed |
+---------------------+------+-------------+--------------+--------------------------+------------------------+ -------------+-----------+------------+
.

 format stdout=
 |@<<<<<<<<<<<<<<<<<<< <| @<<<<| @<<<<<<<<<<<| @<<<<<<<<<<<<| @<<<<<<<<<<<<<<<<<<<<<<<<| @<<<<<<<<<<<<<<<<<<<<<<| @<<<<<<<<<<<| @<<<<<<<<<| @<<<<<<<<<<|
  $st, $http _code, $http _dns_time. " MS ", $http _conn_time." MS ", $http _pre_tran_time." MS ", $http _start_tran_time." MS ", $http _total_time." MS ", $http _size_down." B ", $http _speed_down." b/S "
 +---------------------+------+-------------+--------------+--------------------------+---------- --------------+--------------+----------+------------+
 .
}else{
 print "Error: $err \ n";
}

Sub GetTime ()
{
My @time = (localtime) [5,4,3,2,1,0];
$time [0]+=1900;
$time [1]+=1;
Return sprintf ("%04u-%02u-%02u%02u:%02u:%02u", @time);
}





The same command under the shell command is as follows:

Copy CodeThe code is as follows:
# Curl-o/dev/null-s-W%{http_code}:%{http_connect}:%{time_namelookup}:%{time_connect}:%{time_pretransfer}:%{time _starttransfer}:%{time_total}:%{size_download}:%{speed_download} www.ttlsa.com



No explanation, see Man curl for details.

Use CURL to get the various response times for a site –dns parsing time, response time, transmission time

Copy CodeThe code is as follows:
Curl-o/dev/null-s-W%{http_code}:%{http_connect}:%{content_type}:%{time_namelookup}:%{time_redirect}:%{time_ Pretransfer}:%{time_connect}:%{time_starttransfer}:%{time_total}:%{speed_download} digdeeply.org



This is a my blog site to perform the curl command situation. The output is usually HTML code, which is sent to/dev/null through the-o parameter. The-s parameter removes all state information. The-w parameter lets curl output the status information of the timer.



-dns parsing of each time period in an HTTP request, waiting for server response, getting content, etc.

Below is a detailed explanation of the-w parameter, translated by Me (digdeeply). Please point out the wrong place. (Original in English: http://curl.haxx.se/docs/manpage.html)
The following are the available variable names:

-W,--write-out
The following variables will be in the format of curl as appropriate output, output variables need to follow%{variable_name} format, if you need to output%,double, that is, percent, and \ n is a newline, \ r is the carriage return, \ t is the tab.

Url_effective the URL that is fetched last. This is the most meaningful if you've told Curl to follow Location:headers.

Filename_effective the ultimate filename, the curl writes out to. This was only meaningful if Curl was told to write to a file with the--remote-name or--output option. It ' s most useful in combination with the--remote-header-name option. (Added in 7.25.1)

Http_code HTTP status code, such as 200 success, 301 turn, 404 Not Found, 500 server error, etc. (The numerical response code that is found in the last retrieved HTTP (s) or FTP (s) transfer. In 7.18.2 the alias Response_code is added to show the same info.)

Http_connect the numerical code that is found in the last response (from a proxy) to a Curl connect request. (Added in 7.12.4)

Time_Total total time, in seconds. Accurate to three digits after the decimal point. (The total time, in seconds, then the full operation lasted. The time would be displayed with millisecond resolution.)

Time_namelookup DNS resolution time, from the start of the request to the time that DNS parsing is complete. (The time, in seconds, it took from the start until the name of resolving was completed.)

Time_connect connection time, from start to establish TCP connection to complete the time spent, including the front DNS resolution time, if you need to simply get the connection time, with this time_connect time minus the front time_namelookup time. The following is the same, no longer repeat. (The time, in seconds, it took from the start until the TCP connect to the remote host (or proxy) is completed.)

Time_appconnect Connection Establishment completion time, such as SSL/SSH, etc. to establish a connection or to complete three handshake time. (The time, in seconds, it took from the start until the ssl/ssh/etc Connect/handshake to the remote host was completed. (Added in 7.19.0))

Time_pretransfer the time from the start to the ready transfer. (The time, in seconds, it took from the start until the file transfer is just about to begin. This includes all Pre-transfer commands and negotiations that is specific to the particular protocol (s) involved.)

Time_redirect redirect time, including several redirected DNS resolutions, connections, pre-transmissions, and transfer times before the last transmission. (The time, in seconds, it took for all redirection steps include name lookup, connect, Pretransfer and transfer before the Final transaction was started. Time_redirect shows the complete execution time for multiple redirections. (Added in 7.12.3))

Time_starttransfer Start transfer time. The time it took for the WEB server to return the first byte of data after the request was made (the times, in seconds, the it took from the start until the initial byte was just on to be Tran Sferred. This includes Time_pretransfer and also the time of the server needed to calculate the result.)

size_download Download size. (The total amount of bytes that were downloaded.)

Size_upload upload size. (The total amount of bytes that were uploaded.)

Size_header the size of the header downloaded (the total amount of bytes of the downloaded headers.)

The size of the size_request request. (The total amount of bytes, were sent in the HTTP request.)

Speed_download download speed, units-bytes per second. (The average download speed, the curl measured for the complete download. Bytes per second.)

Speed_upload upload speed, units-bytes per second. (The average upload speed, the curl measured for the complete upload. Bytes per second.)

Content_Type is Content-type, needless to say, this is a visit to my blog home page returned results example (text/html; charset=utf-8); (The content-type of the requested Document, if there is any.)

Num_connects number of new connects made in the recent transfer. (Added in 7.12.3)

Num_redirects number of redirects that were followed in the request. (Added in 7.12.3)

Redirect_url when a HTTP request is made without-l to follow redirects, this variable would show the actual URL a Redirec T would take your to. (Added in 7.18.2)

Ftp_entry_path the initial path Libcurl ended up and logging on to the remote FTP server. (Added in 7.15.4)

Ssl_verify_result SSL authentication results, return 0 indicates successful authentication. (The result of the SSL Peer certificate verification is requested. 0 means the verification was successful. (Added in 7.19.0))

If you use the-w parameter more than once, the output is in the last format. If This option was used several times, the last one would be used.

Http/https Monitoring Get response time (DNS resolution time, RRT time, server processing time, etc.)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.