forked from tsenart/vegeta
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
53 lines (44 loc) · 1.15 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package main
import (
"flag"
"fmt"
"log"
"os"
"runtime"
)
func main() {
commands := map[string]command{"attack": attackCmd(), "report": reportCmd()}
flag.Usage = func() {
fmt.Println("Usage: vegeta [globals] <command> [options]")
for name, cmd := range commands {
fmt.Printf("\n%s command:\n", name)
cmd.fs.PrintDefaults()
}
fmt.Printf("\nglobal flags:\n -cpus=%d Number of CPUs to use\n", runtime.NumCPU())
fmt.Println(examples)
}
cpus := flag.Int("cpus", runtime.NumCPU(), "Number of CPUs to use")
flag.Parse()
runtime.GOMAXPROCS(*cpus)
args := flag.Args()
if len(args) == 0 {
flag.Usage()
os.Exit(1)
}
if cmd, ok := commands[args[0]]; !ok {
log.Fatalf("Unknown command: %s", args[0])
} else if err := cmd.fn(args[1:]); err != nil {
log.Fatal(err)
}
}
const examples = `
examples:
echo "GET http://localhost/" | vegeta attack -duration=5s | tee results.bin | vegeta report
vegeta attack -targets=targets.txt > results.bin
vegeta report -input=results.bin -reporter=json > metrics.json
cat results.bin | vegeta report -reporter=plot > plot.html
`
type command struct {
fs *flag.FlagSet
fn func(args []string) error
}