在这里提到另一种方式。如果您熟悉,可能会有用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)
}
我在这里所做的是,为攻击者对象提供速率、持续时间和目标函数。使用以下命令运行脚本:
go run name_of_the_file.go
NewTextReporter
用于在终端本身打印结果。vegeta
图书馆里还有其他种类的记者。根据要求使用它们。