Mentioning an alternative way here. May be useful if you are familiar with golang
import (
"os"
"time"
"net/http"
vegeta "github.com/tsenart/vegeta/lib"
)
func customTargeter() vegeta.Targeter {
return func(tgt *vegeta.Target) error {
if tgt == nil {
return vegeta.ErrNilTarget
}
tgt.Method = "POST"
tgt.URL = "http://server-ip/api/salon" // your url here
payload := `{
"salon_id" : "562737c1ff567dbd5574c814"
}` // you can make this salon_id dynamic too, using random or uuid
tgt.Body = []byte(payload)
header := http.Header{}
header.Add("Accept", "application/json")
header.Add("Content-Type", "application/json")
tgt.Header = header
return nil
}
}
func main() {
rate := vegeta.Rate{Freq: 1, Per: time.Second} // change the rate here
duration := 1 * time.Minute // change the duration here
targeter := customTargeter()
attacker := vegeta.NewAttacker()
var metrics vegeta.Metrics
for res := range attacker.Attack(targeter, rate, duration, "Whatever name") {
metrics.Add(res)
}
metrics.Close()
reporter := vegeta.NewTextReporter(&metrics)
reporter(os.Stdout)
}
what I am doing here is, providing the Attacker object with rate, duration and a targeter function. Run the script using:
go run name_of_the_file.go
NewTextReporter
is used to print the results in the terminal itself. There are other kinds of reporters available in the vegeta
library. Use them as per requirement.