JoeDog / siege

Siege is an http load tester and benchmarking utility
GNU General Public License v3.0
5.91k stars 386 forks source link

Add option to output the final stats in JSON to stdout #167

Closed bbakersmith closed 4 years ago

bbakersmith commented 4 years ago

I would like to run Siege and interpret the results programmatically, particularly in an automated CI environment. Having the option to print the results as JSON to stdout would make Siege easier to integrate with other scripts and tools.

This PR addresses feature request #151

JoeDog commented 4 years ago

What is your expected output? This is what I get with -j

Eniac $ siege -j -c2 -r2 https://www.joedog.org/ Verbose mode is disabled for JSON output. SIEGE 4.0.4rc3 Preparing 2 concurrent users for battle. The server is now under siege... Transactions: 124 hits Availability: 100.00 % Elapsed time: 9.35 secs Data transferred: 3.76 MB Response time: 0.15 secs Transaction rate: 13.26 trans/sec Throughput: 0.40 MB/sec Concurrency: 1.98 Successful transactions: 124 Failed transactions: 0 Longest transaction: 0.83 Shortest transaction: 0.10

{ "transactions": 124, "availability": 100.00, "elapsed_time": 9.35, "data_transferred": 3.76, "response_time": 0.15, "transaction_rate": 13.26, "throughput": 0.40, "concurrency": 1.98, "successful_transactions": 124, "failed_transactions": 0, "longest_transaction": 0.83, "shortest_transaction": 0.10 }

I would suggest forcing it into quiet mode like thisL

Eniac $ siege -q -j -c2 -r2 https://www.joedog.org/

{ "transactions": 124, "availability": 100.00, "elapsed_time": 9.43, "data_transferred": 3.76, "response_time": 0.15, "transaction_rate": 13.15, "throughput": 0.40, "concurrency": 1.97, "successful_transactions": 124, "failed_transactions": 0, "longest_transaction": 0.85, "shortest_transaction": 0.09 }

bbakersmith commented 4 years ago

Forcing quiet mode is a fine approach. I considered that but figured I'd make the smallest change possible to existing functionality, and all the non-JSON output (besides verbose and debug which I disabled for json_output) goes to stderr, so it looks a little goofy in your first example but doesn't interfere with piping or redirecting stdout.

I just pushed a change to the PR that sets quiet mode instead.

bbakersmith commented 4 years ago

To test for valid JSON output I've been using jq

$ siege -j -c2 https://www.joedog.org/ | jq

And to extract a specific value

$ siege -j -c2 https://www.joedog.org/ | jq .transactions
bbakersmith commented 4 years ago

This still prints Lifting the server siege... in addition to the JSON output. That's not a problem functionally because it goes to stderr, but do you think it should be silenced too? And if so do you think it should be silenced for quiet mode generally or just json_output?

JoeDog commented 4 years ago

I'll look at it tomorrow. In quiet, that should be silent, too. That's probably a bug.

On Sun, Feb 9, 2020 at 5:57 PM Ben Baker-Smith notifications@github.com wrote:

This still prints Lifting the server siege... in addition to the JSON output. That's not a problem functionally because it goes to stderr, but do you think it should be silenced too? And if so do you think it should be silenced for quiet mode generally or just json_output?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/JoeDog/siege/pull/167?email_source=notifications&email_token=ABJRHZXCP2SBN5D5XUB26P3RCCC43A5CNFSM4KSCZJ7KYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOELG2YMY#issuecomment-583904307, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABJRHZRCYDAPMITD75TTHRLRCCC43ANCNFSM4KSCZJ7A .

bbakersmith commented 4 years ago

This was merged in manually today, closing the PR.