http-timing
v2.0.1
Published
generate the http timing(server timing) view
Downloads
3
Maintainers
Readme
http-timing
Generate the http timing(Server-Timing)
API
Constructor
The HTTPTiming constructor
options
The constructor optionsoptions.max
The max time(ms), use for the time line bar, default is 10 * 1000options.size
The cache size, default is 10
const HTTPTiming = require('http-timing');
const httpTiming = new HTTPTiming({
max: 5 * 1000,
size: 5,
});
add
Add the data to timing view, return function to change the value of data
data
The setting of http timingdata.url
The http request urldata.method
The http request methoddata.status
The http response statusdata.use
The http response timedata.serverTiming
The http server timing
const HTTPTiming = require('http-timing');
const httpTiming = new HTTPTiming();
const set = httpTiming.add({
method: 'GET',
url: '/users/me',
status: 200,
use: 3000,
serverTiming: 'A;dur=2521.46147;desc="/users/me",B;dur=102.022688;desc="getUser",C;dur=33.468153;desc="mongodb:get",D;dur=54.064163;desc="validate:user"',
});
set('use', 5000);
set({
use: 5000,
});
get
Get the timing by index
index
the timing index
const HTTPTiming = require('http-timing');
const httpTiming = new HTTPTiming();
httpTiming.add({
method: 'GET',
url: '/users/me',
status: 200,
use: 3000,
serverTiming: 'A;dur=2521.46147;desc="/users/me",B;dur=102.022688;desc"getUser",C;dur=33.468153;desc"mongodb:get",D;dur=54.064163;desc="validate:user"',
});
console.info(httpTiming.get(0));
length
Get the cache length
const HTTPTiming = require('http-timing');
const httpTiming = new HTTPTiming();
// 0
console.info(httpTiming.length);
empty
Remove all cache
const HTTPTiming = require('http-timing');
const httpTiming = new HTTPTiming();
httpTiming.add({
method: 'GET',
url: '/users/me',
status: 200,
use: 3000,
serverTiming: 'A;dur=2521.46147;desc="/users/me",B;dur=102.022688;desc="getUser",C;dur=33.468153;desc="mongodb:get",D;dur=54.064163;desc="validate:user"',
});
// 1
console.info(httpTiming.length)
httpTiming.empty();
// 0
console.info(httpTiming.length)
toHTML
Get the html of http timing
const HTTPTiming = require('http-timing');
const httpTiming = new HTTPTiming();
httpTiming.add({
method: 'GET',
url: '/users/me',
status: 200,
use: 3000,
serverTiming: 'A;dur=2521.46147;desc="/users/me",B;dur=102.022688;desc="getUser",C;dur=33.468153;desc="mongodb:get",D;dur=54.064163;desc="validate:user"',
});
const html = httpTiming.toHTML();
console.info(html);
License
MIT