Parameterize reporter output file

This commit is contained in:
Tomás Senart
2013-08-14 17:48:51 +02:00
parent c065e699e3
commit fe12ab2e9b
2 changed files with 23 additions and 3 deletions

View File

@@ -18,6 +18,7 @@ $ vegeta -h
Usage of vegeta: Usage of vegeta:
-duration=10s: Duration of the test -duration=10s: Duration of the test
-ordering="random": Attack ordering [sequential, random] -ordering="random": Attack ordering [sequential, random]
-output="stdout": Reporter output file
-rate=50: Requests per second -rate=50: Requests per second
-reporter="text": Reporter to use [text] -reporter="text": Reporter to use [text]
-targets="targets.txt": Targets file -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 The other option is `sequential` and it does what you would expect it to
do. do.
#### -output
Specifies the output file to which the report will be written to.
The default is stdout.
#### -rate #### -rate
Specifies the requests per second rate to issue requests with against Specifies the requests per second rate to issue requests with against
the targets the targets

21
main.go
View File

@@ -2,6 +2,7 @@ package main
import ( import (
"flag" "flag"
"io"
"log" "log"
"math" "math"
"math/rand" "math/rand"
@@ -18,6 +19,7 @@ func main() {
ordering = flag.String("ordering", "random", "Attack ordering [sequential, random]") ordering = flag.String("ordering", "random", "Attack ordering [sequential, random]")
duration = flag.Duration("duration", 10*time.Second, "Duration of the test") duration = flag.Duration("duration", 10*time.Second, "Duration of the test")
reporter = flag.String("reporter", "text", "Reporter to use [text]") reporter = flag.String("reporter", "text", "Reporter to use [text]")
output = flag.String("output", "stdout", "Reporter output file")
) )
flag.Parse() flag.Parse()
@@ -58,12 +60,25 @@ func main() {
rep = NewTextReporter() 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) 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! // Report results!
if rep.Report(os.Stdout) != nil { log.Printf("Writing report to '%s'...", *output)
log.Fatal("Failed to report!") if rep.Report(out) != nil {
log.Println("Failed to report!")
} }
} }