From fe12ab2e9b796dfe035580ba0ebeb6a37d857b6b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1s=20Senart?= Date: Wed, 14 Aug 2013 17:48:51 +0200 Subject: [PATCH] Parameterize reporter output file --- README.md | 5 +++++ main.go | 21 ++++++++++++++++++--- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 3282fb7..1696093 100644 --- a/README.md +++ b/README.md @@ -18,6 +18,7 @@ $ vegeta -h Usage of vegeta: -duration=10s: Duration of the test -ordering="random": Attack ordering [sequential, random] + -output="stdout": Reporter output file -rate=50: Requests per second -reporter="text": Reporter to use [text] -targets="targets.txt": Targets file @@ -36,6 +37,10 @@ that target again. The other option is `sequential` and it does what you would expect it to do. +#### -output +Specifies the output file to which the report will be written to. +The default is stdout. + #### -rate Specifies the requests per second rate to issue requests with against the targets diff --git a/main.go b/main.go index dc85f53..f18afa3 100644 --- a/main.go +++ b/main.go @@ -2,6 +2,7 @@ package main import ( "flag" + "io" "log" "math" "math/rand" @@ -18,6 +19,7 @@ func main() { ordering = flag.String("ordering", "random", "Attack ordering [sequential, random]") duration = flag.Duration("duration", 10*time.Second, "Duration of the test") reporter = flag.String("reporter", "text", "Reporter to use [text]") + output = flag.String("output", "stdout", "Reporter output file") ) flag.Parse() @@ -58,12 +60,25 @@ func main() { rep = NewTextReporter() } - log.Printf("Vegeta is attacking %d targets in %s order for %s\n", len(targets), *ordering, *duration) + log.Printf("Vegeta is attacking %d targets in %s order for %s...\n", len(targets), *ordering, *duration) attack(targets, *ordering, *rate, *duration, rep) + log.Println("Done!") + var out io.WriteCloser + switch *output { + case "stdout": + out = os.Stdout + default: + out, err = os.Create(*output) + if err != nil { + log.Printf("Couldn't open `%s` for writing report: %s", *output, err) + } + defer out.Close() + } // Report results! - if rep.Report(os.Stdout) != nil { - log.Fatal("Failed to report!") + log.Printf("Writing report to '%s'...", *output) + if rep.Report(out) != nil { + log.Println("Failed to report!") } }