Parameterize reporter output file
This commit is contained in:
@@ -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
|
||||
|
||||
21
main.go
21
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!")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user