HTTP load generator, ApacheBench (ab) replacement
Go
Added a CSV output option
Pascal Hakim22b457a0803c
diff --git a/commands/boom.go b/commands/boom.goindex b95dc82..bd63701 100644--- a/commands/boom.go+++ b/commands/boom.go@@ -41,6 +41,9 @@ type Boom struct {// Option to allow insecure TLS/SSL certificates.AllowInsecure bool+ // Output type+ Output string+bar *pb.ProgressBarrpt *reportresults chan *resultdiff --git a/commands/print.go b/commands/print.goindex 611e5c5..6e25b82 100644--- a/commands/print.go+++ b/commands/print.go@@ -37,12 +37,15 @@ type report struct {statusCodeDist map[int]intlats []float64++ output string}-func newReport(size int, results chan *result) *report {+func newReport(size int, results chan *result, output string) *report {return &report{statusCodeDist: make(map[int]int),results: results,+ output: output,}}@@ -66,17 +69,28 @@ func (r *report) finalize(total time.Duration) {func (r *report) print() {if len(r.lats) > 0 {sort.Float64s(r.lats)- r.fastest = r.lats[0]- r.slowest = r.lats[len(r.lats)-1]- fmt.Printf("\nSummary:\n")- fmt.Printf(" Total:\t%4.4f secs.\n", r.total.Seconds())- fmt.Printf(" Slowest:\t%4.4f secs.\n", r.slowest)- fmt.Printf(" Fastest:\t%4.4f secs.\n", r.fastest)- fmt.Printf(" Average:\t%4.4f secs.\n", r.average)- fmt.Printf(" Requests/sec:\t%4.4f\n", r.rps)- r.printStatusCodes()- r.printHistogram()- r.printLatencies()++ if r.output == "txt" {+ r.fastest = r.lats[0]+ r.slowest = r.lats[len(r.lats)-1]+ fmt.Printf("\nSummary:\n")+ fmt.Printf(" Total:\t%4.4f secs.\n", r.total.Seconds())+ fmt.Printf(" Slowest:\t%4.4f secs.\n", r.slowest)+ fmt.Printf(" Fastest:\t%4.4f secs.\n", r.fastest)+ fmt.Printf(" Average:\t%4.4f secs.\n", r.average)+ fmt.Printf(" Requests/sec:\t%4.4f\n", r.rps)+ r.printStatusCodes()+ r.printHistogram()+ r.printLatencies()+ } else if r.output == "csv" {+ r.printCSV()+ }+ }+}++func (r *report) printCSV() {+ for i := 0; i < 100; i++ {+ fmt.Printf("%v,%4.4f\n", i+1, r.lats[i*len(r.lats)/100])}}diff --git a/commands/run.go b/commands/run.goindex 0422d99..b63b517 100644--- a/commands/run.go+++ b/commands/run.go@@ -24,7 +24,7 @@ import (func (b *Boom) Run() {b.results = make(chan *result, b.N)b.bar = newPb(b.N)- b.rpt = newReport(b.N, b.results)+ b.rpt = newReport(b.N, b.results, b.Output)b.run()}diff --git a/main.go b/main.goindex ef8b226..cbfa1a9 100644--- a/main.go+++ b/main.go@@ -32,6 +32,7 @@ var (flagType = flag.String("T", "text/html", "")flagAuth = flag.String("a", "", "")flagInsecure = flag.Bool("allow-insecure", false, "")+ flagOutput = flag.String("o", "txt", "")flagC = flag.Int("c", 50, "")flagN = flag.Int("n", 200, "")@@ -55,6 +56,7 @@ Options:-allow-insecure Allow bad/expired TLS/SSL certificates.+ -o Output type, one of txt, csv`func main() {@@ -112,7 +114,11 @@ func main() {req.SetBasicAuth(matches[0][1], matches[0][2])}- (&commands.Boom{N: n, C: c, Qps: q, Timeout: t, Req: req, AllowInsecure: *flagInsecure}).Run()+ if *flagOutput != "csv" && *flagOutput != "txt" {+ usageAndExit()+ }++ (&commands.Boom{N: n, C: c, Qps: q, Timeout: t, Req: req, AllowInsecure: *flagInsecure, Output: *flagOutput}).Run()}func usageAndExit() {