Created
January 21, 2020 09:57
-
-
Save skimi/97ca74d32735efa5a8b2e3dfacd3de31 to your computer and use it in GitHub Desktop.
analysis-har-network.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const fs = require('fs'); | |
const groupBy = require('lodash/groupBy'); | |
const filePath = process.argv[2]; | |
const file = JSON.parse(fs.readFileSync(filePath, 'utf8')); | |
const files = file.log.entries.map((entry) => { | |
const url = new URL(entry.request.url); | |
return { | |
type: url.host.includes('manager') ? 'internal' : 'external', | |
size: entry.response._transferSize, | |
host: url.host, | |
} | |
}) | |
const byHost = Object.entries(groupBy(files, (file) => file.host)).map(([host, values]) => { | |
return { | |
host, | |
size: values.reduce((carry, file) => carry + file.size, 0), | |
type: values[0].type, | |
} | |
}); | |
console.log('host,size,type'); | |
byHost.forEach((host) => { | |
console.log(`"${host.host}","${host.size}","${host.type}"`) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment