stream-log-stats
Advanced tools
Comparing version 1.1.7 to 2.0.0
'use strict' | ||
var path = require('path') | ||
var urlUtil = require('url') | ||
var byteSize = require('byte-size') | ||
const path = require('path') | ||
const urlUtil = require('url') | ||
const byteSize = require('byte-size') | ||
var stats = module.exports = { | ||
const stats = module.exports = { | ||
clients: {}, | ||
@@ -35,4 +35,4 @@ clientCount: 0, | ||
} | ||
var parsedUrl = urlUtil.parse(url) | ||
var type = path.extname(parsedUrl.pathname) || '<none>' | ||
const parsedUrl = urlUtil.parse(url) | ||
let type = path.extname(parsedUrl.pathname) || '<none>' | ||
type = type.toLowerCase() | ||
@@ -52,15 +52,17 @@ if (stats.type[type]) { | ||
Object.keys(stats.resource).forEach(function (key) { | ||
var resource = stats.resource[key] | ||
const resource = stats.resource[key] | ||
const { value, unit } = byteSize(resource.bytes, { units: 'iec', precision: 2 }) | ||
stats.topResources.push({ | ||
resource: key, | ||
requests: resource.requests, | ||
bytes: byteSize(resource.bytes, { units: 'iec', precision: 2 }) | ||
bytes: `${value} ${unit}` | ||
}) | ||
}) | ||
Object.keys(stats.type).forEach(function (key) { | ||
var type = stats.type[key] | ||
const type = stats.type[key] | ||
const { value, unit } = byteSize(type.bytes, { units: 'iec', precision: 2 }) | ||
stats.topTypes.push({ | ||
type: key, | ||
requests: type.requests, | ||
bytes: byteSize(type.bytes, { units: 'iec', precision: 2 }) | ||
bytes: `${value} ${unit}` | ||
}) | ||
@@ -78,3 +80,4 @@ }) | ||
this.bytes += bytes | ||
this.transferred = byteSize(this.bytes, { units: 'iec', precision: 2 }) | ||
const { value, unit } = byteSize(this.bytes, { units: 'iec', precision: 2 }) | ||
this.transferred = `${value} ${unit}` | ||
} |
'use strict' | ||
var Clf = require('common-log-format') | ||
var view = require('./view') | ||
var stats = require('./stats') | ||
var JSONStream = require('JSONStream') | ||
var streamVia = require('stream-via') | ||
var throttle = require('lodash.throttle') | ||
const Clf = require('common-log-format') | ||
const view = require('./view') | ||
const stats = require('./stats') | ||
const JSONStream = require('JSONStream') | ||
const streamVia = require('stream-via') | ||
const throttle = require('lodash.throttle') | ||
@@ -13,10 +13,10 @@ module.exports = streamLogStats | ||
options = options || {} | ||
var throttledRender = throttle(view.render, options.refreshRate || 500) | ||
const throttledRender = throttle(view.render, options.refreshRate || 500) | ||
function renderLogObject (logObject) { | ||
var requestSplit = logObject.request.split(' ') | ||
const requestSplit = logObject.request.split(' ') | ||
stats.addBytes(logObject.bytes) | ||
stats.requests++ | ||
stats.addClient(logObject.remoteHost) | ||
var resourceLine | ||
let resourceLine | ||
try { | ||
@@ -29,7 +29,7 @@ resourceLine = decodeURI(requestSplit[1]) | ||
stats.addResource(logObject.status + ' ' + requestSplit[0] + ' ' + resourceLine, logObject.bytes) | ||
throttledRender(stats) | ||
} | ||
var clf = new Clf(options) | ||
const clf = new Clf(options) | ||
clf | ||
@@ -36,0 +36,0 @@ .pipe(JSONStream.parse()) |
'use strict' | ||
var ansi = require('ansi-escape-sequences') | ||
var tableLayout = require('table-layout') | ||
const ansi = require('ansi-escape-sequences') | ||
const Table = require('table-layout') | ||
exports.render = render | ||
var visible = false | ||
var previouslyRenderedLines = 0 | ||
let visible = false | ||
let previouslyRenderedLines = 0 | ||
function render (stats) { | ||
var clientsData = [ | ||
const clientsTable = new Table([ | ||
{ | ||
@@ -22,6 +22,5 @@ one: ansi.format('Clients', ['underline']), | ||
} | ||
] | ||
var clientsTable = tableLayout(clientsData) | ||
]) | ||
var extensionTable = tableLayout([ | ||
const extensionTable = new Table([ | ||
{ | ||
@@ -34,7 +33,6 @@ type: ansi.format('Extension', ['underline']), | ||
stats.topResources = stats.topResources.map(function (resourceLine) { | ||
var availableSpace = process.stdout.columns - 37 | ||
stats.topResources = stats.topResources.map(resourceLine => { | ||
const availableSpace = process.stdout.columns - 37 | ||
if (resourceLine.resource.length > availableSpace) { | ||
var split = resourceLine.resource.split(/\s+/) | ||
const split = resourceLine.resource.split(/\s+/) | ||
resourceLine.resource = split[0] + ' ' + split[1] + ' ...' + split[2].substr(-(availableSpace)) | ||
@@ -45,3 +43,3 @@ } | ||
var resourceTable = tableLayout( | ||
const resourceTable = new Table( | ||
[ | ||
@@ -59,3 +57,3 @@ { | ||
var output = clientsTable + '\n' + extensionTable + '\n' + resourceTable | ||
const output = clientsTable + '\n' + extensionTable + '\n' + resourceTable | ||
@@ -70,6 +68,6 @@ if (visible) { | ||
process.stderr.write(ansi.erase.display()) | ||
var lines = output.split('\n') | ||
const lines = output.split('\n') | ||
previouslyRenderedLines = 0 | ||
for (var i = 0; i < lines.length && i < (process.stdout.rows - 2); i++) { | ||
for (let i = 0; i < lines.length && i < (process.stdout.rows - 2); i++) { | ||
console.error(lines[i]) | ||
@@ -76,0 +74,0 @@ previouslyRenderedLines++ |
{ | ||
"name": "stream-log-stats", | ||
"author": "Lloyd Brookes <75pound@gmail.com>", | ||
"version": "1.1.7", | ||
"version": "2.0.0", | ||
"description": "Prints statistics from the incoming web log stream to the console", | ||
@@ -21,19 +21,19 @@ "repository": "https://github.com/75lb/stream-log-stats.git", | ||
"engines": { | ||
"node": ">=0.10.0" | ||
"node": ">=4.0.0" | ||
}, | ||
"scripts": { | ||
"test": "tape test/*.js" | ||
"test": "test-runner test/*.js" | ||
}, | ||
"devDependencies": { | ||
"tape": "^4.6.0" | ||
"test-runner": "^0.3.0" | ||
}, | ||
"dependencies": { | ||
"JSONStream": "^1.1.2", | ||
"ansi-escape-sequences": "^2.2.2", | ||
"byte-size": "^2.0.0", | ||
"JSONStream": "^1.3.1", | ||
"ansi-escape-sequences": "^3.0.0", | ||
"byte-size": "^3.0.0", | ||
"common-log-format": "~0.1.3", | ||
"lodash.throttle": "^4.0.1", | ||
"lodash.throttle": "^4.1.1", | ||
"stream-via": "^1.0.3", | ||
"table-layout": "~0.2.2" | ||
"table-layout": "~0.4.0" | ||
} | ||
} |
@@ -74,2 +74,2 @@ [![view on npm](http://img.shields.io/npm/v/stream-log-stats.svg)](https://www.npmjs.org/package/stream-log-stats) | ||
© 2015-16 Lloyd Brookes \<75pound@gmail.com\>. | ||
© 2015-17 Lloyd Brookes \<75pound@gmail.com\>. |
@@ -1,8 +0,9 @@ | ||
var test = require('tape') | ||
var statsView = require('../') | ||
const statsView = require('../') | ||
const TestRunner = require('test-runner') | ||
test('first', function (t) { | ||
var view = statsView() | ||
const runner = new TestRunner() | ||
runner.test('first', function (t) { | ||
const view = statsView() | ||
view.write('{"remoteHost":"127.0.0.1","remoteLogName":"-","authUser":"-","date":"2014-06-11T16:24:02.000Z","request":"GET / HTTP/1.1","status":200,"bytes":10305}{"remoteHost":"127.0.0.1","remoteLogName":"-","authUser":"-","date":"2014-06-11T16:24:08.000Z","request":"GET /package.json HTTP/1.1","status":304,"bytes":null}') | ||
t.end() | ||
}) |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
10648
183
+ Addedarray-back@2.0.0(transitive)
+ Addedbyte-size@3.0.0(transitive)
+ Addeddeep-extend@0.6.0(transitive)
+ Addedlodash.padend@4.6.1(transitive)
+ Addedtable-layout@0.4.5(transitive)
+ Addedwordwrapjs@3.0.0(transitive)
- Removedansi-escape-sequences@2.2.2(transitive)
- Removedbyte-size@2.0.0(transitive)
- Removedcollect-all@0.2.11.0.4(transitive)
- Removedcollect-json@1.0.9(transitive)
- Removedcommand-line-args@3.0.5(transitive)
- Removedcommand-line-tool@0.6.4(transitive)
- Removedcommand-line-usage@3.0.8(transitive)
- Removedcore-js@2.6.12(transitive)
- Removeddeep-extend@0.4.2(transitive)
- Removedfeature-detect-es6@1.5.0(transitive)
- Removedfind-replace@1.0.3(transitive)
- Removedstream-connect@1.0.2(transitive)
- Removedstream-via@0.1.1(transitive)
- Removedtable-layout@0.2.30.3.0(transitive)
- Removedtest-value@2.1.0(transitive)
- Removedwordwrapjs@1.2.12.0.0(transitive)
UpdatedJSONStream@^1.3.1
Updatedansi-escape-sequences@^3.0.0
Updatedbyte-size@^3.0.0
Updatedlodash.throttle@^4.1.1
Updatedtable-layout@~0.4.0