http-metrics

0.1.0 • Public • Published

http-metrics

Build Status Dependency 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.

Installation

$ npm install http-metrics

Usage

request(options, cb)

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

example:

// http request
var q = require('http-metrics');
q.request({
  hostname: 'www.sina.com.cn',
  port: 80,
  path: '/',
  method: 'GET'
}, 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 }
 */
 
// https request
var q = require('http-metrics');
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 }
 */

Package Sidebar

Install

npm i http-metrics

Weekly Downloads

1

Version

0.1.0

License

MIT

Last publish

Collaborators

  • taevas