Skip to content

Instantly share code, notes, and snippets.

@photopresentr
Created December 15, 2013 16:04
Show Gist options
  • Save photopresentr/7974747 to your computer and use it in GitHub Desktop.
Save photopresentr/7974747 to your computer and use it in GitHub Desktop.
Convert HAR Archive to Siege URL List using node.js
#!/usr/bin/env node
/*
* har2siege.js
* converts a HAR file generated by chrome to an url file as required
* by the siege performance testing tool (http://www.joedog.org/siege-home/)
*
* Usage:
* - save har file in chrome. make sure extension is .json, e.g. myrequests.json
* - put the relative path as the only parameter on the command line
* - redirect STDOUT to the file you want as the urllist for siege
*
* Example: ./har2siege.js ./myrequests.json > ./urllist.txt
*/
var har = require(process.argv[2]);
var _ = require('underscore');
process.stdout.write(
_.map(har.log.entries, function(entry) {
return entry.request.url +
(entry.request.method =='POST' ? ' POST ' + entry.request.postData.text : '');
}).join('\n'));
@photopresentr
Copy link
Author

Convert Chrome HTTP Request Archive (HAR) to a Siege URL List for benchmarking

In the Chrome Developer Tools, under the Network Panel, you can receive a list of all HTTP requests made by a page. With a right click, you can open the context menu and choose "Save as HAR with Content". This saves a little JSON file on your disk which contains a record of all the requests made in the session.

This is almost what you need to do performance testing of your single page app with the Siege (http://www.joedog.org/siege-home/) open source tool. You only need to convert the HAR file to a simple text file, which is what the script in this gist does.

How to

  • It is required to already have node.js installed
  • underscore.js is also required; if you don't have it, install by typing npm -g install underscore (as root) on the console
  • Save the har2siege.js file on your disk. Save also the HAR file from Chrome as instructed above, making sure you save the file with extension .json, in the same directory.
  • Then run ./har2siege.js ./myrequests.json > urllist.txt

The program writes out one request per line. In case of POST requests, it also puts the POST data as required by siege. Now you can benchmark your app with siege!

For example, run siege -c10 -d5 -v -f urllist.txt to simulate

  • 10 simultaneous users
  • a random delay between 0 and 5 seconds per request
  • with verbose output
  • taking the URLs from the file just created

Other Projects

@kuddl
Copy link

kuddl commented Jan 21, 2015

Hi.
I made an alternate Version to not use underscore .. https://gist.github.com/kuddl/5a3104b2c6e66839cf69

Thanks for your initial work!
Tobias

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment