https://github.com/vicanso/http-performance
Get the http perfomance
https://github.com/vicanso/http-performance
http http-perf http-performance performance
Last synced: 3 months ago
JSON representation
Get the http perfomance
- Host: GitHub
- URL: https://github.com/vicanso/http-performance
- Owner: vicanso
- Created: 2017-08-02T13:25:33.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2017-08-31T00:15:19.000Z (over 8 years ago)
- Last Synced: 2025-01-28T04:33:35.454Z (about 1 year ago)
- Topics: http, http-perf, http-performance, performance
- Language: JavaScript
- Size: 32.2 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# http-performance
I use `httpstat` to test my rest api's performance and then I want to write a module to get the performance of `http`.
The moudle can get the request and response of `http`, including `dns`, `method`, `url` and so on.
[](https://travis-ci.org/vicanso/http-performance)
[](https://coveralls.io/r/vicanso/http-performance?branch=master)
[](https://www.npmjs.org/package/http-performance)
[](https://github.com/vicanso/http-performance)
## API
```js
// please require the module first
const httpPerf = require('http-performance');
const http = require('http');
httpPerf.on('stats', (stats) => {
/* { category: 'request',
dns: { ip: '14.215.177.38', addressType: 4 },
requesting: 0,
method: 'GET',
host: 'www.baidu.com',
url: '/',
status: 200,
bytes: 15358,
timing: { socket: 9, dns: 2, tcp: 6, processing: 13, transfer: 5, all: 35 } }
*/
console.info(stats);
});
http.get('http://www.baidu.com/');
```
```js
// please require the module first
const httpPerf = require('http-performance');
const http = require('http');
const express = require('express');
httpPerf.on('stats', (stats) => {
if (stats.type !== 'response') {
return;
}
/* { category: 'response',
method: 'GET',
timing: { all: 1013, socket: 0 },
status: 200,
url: '/',
bytes: 60,
responsing: 0 }
*/
console.info(stats);
});
const app = express();
app.use((req, res, next) => setTimeout(next, 1000));
app.use((req, res) => {
res.json({
message: 'hello world',
});
});
const server = app.listen();
const url = `http://127.0.0.1:${server.address().port}`;
http.get(url);
```
### disable/enable
- type The http type, 'request' or 'response'
Diable or enable the http stats type, default is enabled.
```js
const httpPerf = require('http-performance');
httpPerf.disable('request');
httpPerf.enable('request');
```
## License
MIT