Skip to content

Instantly share code, notes, and snippets.

@skimi
Created January 21, 2020 09:57
Show Gist options
  • Save skimi/97ca74d32735efa5a8b2e3dfacd3de31 to your computer and use it in GitHub Desktop.
Save skimi/97ca74d32735efa5a8b2e3dfacd3de31 to your computer and use it in GitHub Desktop.
analysis-har-network.js
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