using stream-log-stats
This commit is contained in:
36
bin/ws.js
36
bin/ws.js
@ -13,7 +13,9 @@ var dope = require("console-dope"),
|
|||||||
directory = require("serve-index"),
|
directory = require("serve-index"),
|
||||||
compress = require("compression"),
|
compress = require("compression"),
|
||||||
homePath = require("home-path"),
|
homePath = require("home-path"),
|
||||||
byteSize = require("byte-size");
|
byteSize = require("byte-size"),
|
||||||
|
clf = require("common-log-format"),
|
||||||
|
logStats = require("stream-log-stats");
|
||||||
|
|
||||||
var usage =
|
var usage =
|
||||||
"usage: \n\
|
"usage: \n\
|
||||||
@ -86,14 +88,13 @@ if (argv.config){
|
|||||||
|
|
||||||
var app = connect();
|
var app = connect();
|
||||||
|
|
||||||
/* log using --log-format (if supplied), else output statics */
|
/* log using --log-format (if supplied) */
|
||||||
if(argv["log-format"]){
|
if(argv["log-format"]) {
|
||||||
app.use(morgan(argv["log-format"]));
|
app.use(morgan(argv["log-format"]));
|
||||||
} else {
|
} else {
|
||||||
app.use(function(req, res, next){
|
var statStream = clf();
|
||||||
dope.column(1).write(++total.req);
|
statStream.pipe(logStats());
|
||||||
next();
|
app.use(morgan({ stream: statStream }));
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* --compress enables compression */
|
/* --compress enables compression */
|
||||||
@ -120,25 +121,4 @@ if (argv.config){
|
|||||||
} else {
|
} else {
|
||||||
dope.error("serving %underline{%s} at %underline{%s}", argv.directory, "http://localhost:" + argv.port);
|
dope.error("serving %underline{%s} at %underline{%s}", argv.directory, "http://localhost:" + argv.port);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* in stats mode, monitor connections and bytes transferred */
|
|
||||||
if (!argv["log-format"]){
|
|
||||||
dope.hideCursor();
|
|
||||||
dope.log("%underline{Requests} %underline{Data} %underline{Connections}");
|
|
||||||
server.on("connection", function(socket){
|
|
||||||
var oldWrite = socket.write;
|
|
||||||
socket.write = function(data) {
|
|
||||||
if (!Buffer.isBuffer(data)) {
|
|
||||||
data = new Buffer(data);
|
|
||||||
}
|
|
||||||
oldWrite.call(this, data);
|
|
||||||
total.bytes += data.length;
|
|
||||||
dope.column(12).write(s.padRight(byteSize(total.bytes, 2), 12));
|
|
||||||
};
|
|
||||||
dope.column(24).write(++total.connections);
|
|
||||||
socket.on("close", function(){
|
|
||||||
dope.column(24).write(s.padRight(--total.connections));
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -16,6 +16,7 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"byte-size": "^0.1.0",
|
"byte-size": "^0.1.0",
|
||||||
"command-line-args": "^0.2.0",
|
"command-line-args": "^0.2.0",
|
||||||
|
"common-log-format": "^0.1.2",
|
||||||
"compression": "^1.0.2",
|
"compression": "^1.0.2",
|
||||||
"config-master": "~0.1.0",
|
"config-master": "~0.1.0",
|
||||||
"connect": "^3.0.0",
|
"connect": "^3.0.0",
|
||||||
@ -25,6 +26,7 @@
|
|||||||
"object-ting": "^1.0.0",
|
"object-ting": "^1.0.0",
|
||||||
"serve-index": "^1.0.2",
|
"serve-index": "^1.0.2",
|
||||||
"serve-static": "^1.2.2",
|
"serve-static": "^1.2.2",
|
||||||
|
"stream-log-stats": "0.0.1",
|
||||||
"string-ting": "0.0.1"
|
"string-ting": "0.0.1"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user