0.1.11 • Published 7 years ago

hmetrics v0.1.11

Weekly downloads
1
License
MIT
Repository
github
Last release
7 years ago

http-metrics

npm Build Status Dependency Status Coverage Status devDependency Status Codacy Badge

Make HTTP/HTTPS display information on callback after a completed transfer.

The variables available are:

  • time_namelookup The time, in seconds, it took from the start until the name resolving was completed.
  • time_appconnect The time, in seconds, it took from the start until the SSL/SSH/etc connect/handshake to the remote host was completed.
  • time_connect The time, in seconds, it took from the start until the TCP connect to the remote host (or proxy) was completed.
  • time_starttransfer The time, in seconds, it took from the start until the first byte was just about to be transferred. This includes time_pretransfer and also the time the server needed to calculate the result.
  • time_total The total time, in seconds, that the full operation lasted. The time will be displayed with millisecond resolution.
  • size_download Number of bytes downloaded.
  • status_code HTTP response status code.

Installation

$ npm install hmetrics

Usage

request(options, cb)

options can be an object or a string. All options from http/https are valid.

extra-options:

  • timeout set maximum time the request is allowed to take
  • connect_timeout timeout for the connect phase

example:

// http request
var q = require('hmetrics');
q.request({
  hostname: 'www.sina.com.cn',
  port: 80,
  path: '/',
  method: 'GET',
  timeout: 10,
  connect_timeout: 5
}, function(err, data) {
  if (err) return console.log(err);
  console.log(data);
});
/**
 * { time_namelookup: 0.012,
 *   time_total: 0.036,
 *   time_appconnect: 0,
 *   time_connect: 0.018,
 *   time_starttransfer: 0.032,
 *   size_download: 298816,
 *   status_code: 200 }
 */

// https request
var q = require('hmetrics');
q.request('https://www.baidu.com', function(err, data) {
  if (err) return console.log(err);
  console.log(data);
});
/**
 * { time_namelookup: 0.021,
 *   time_starttransfer: 0.065,
 *   time_total: 0.067,
 *   time_appconnect: 0.053,
 *   time_connect: 0.032,
 *   size_download: 298816,
 *   status_code: 200 }
 */

// http request timeout
var q = require('hmetrics');

q.request({
  hostname: 'www.sina.com.cn',
  port: 80,
  path: '/',
  method: 'GET',
  timeout: 10,
  connect_timeout: 0.0001
}, function(err, data) {
  if (err) return console.log(err);
  console.log(data);
});
/**
 * [Error: request timeout]
 */