-
Notifications
You must be signed in to change notification settings - Fork 189
/
txgen.go
62 lines (55 loc) · 1.34 KB
/
txgen.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
54
55
56
57
58
59
60
61
62
package service
import (
"bytes"
"fmt"
"text/template"
)
type TxGenService struct {
Name string
IP string
TargetUrl string
Rate int
ThreadSize int
ConnSize int
Duration string
}
func NewTxGenService(ip string, targetUrl string, opt TxGenOption) *TxGenService {
return &TxGenService{
Name: "txgen",
IP: ip,
TargetUrl: targetUrl,
Rate: opt.TxGenRate,
ThreadSize: opt.TxGenThreadSize,
ConnSize: opt.TxGenConnSize,
Duration: opt.TxGenDuration,
}
}
func (s TxGenService) String() string {
tmpl, err := template.New("TxGen").Parse(dockerComposeTemplate)
if err != nil {
fmt.Printf("Failed to parse template, %v", err)
return ""
}
result := new(bytes.Buffer)
err = tmpl.Execute(result, s)
if err != nil {
fmt.Printf("Failed to render template, %v", err)
return ""
}
return result.String()
}
var dockerComposeTemplate = `{{ .Name }}:
hostname: {{ .Name }}
image: 428948643293.dkr.ecr.ap-northeast-2.amazonaws.com/groundx/txgen:latest
entrypoint: ["txgen", "-r", "{{ .Rate }}", "-t", "{{ .ThreadSize }}", "-c", "{{ .ConnSize }}", "-d", "{{ .Duration }}", "{{ .TargetUrl }}"]
networks:
app_net:
ipv4_address: {{ .IP }}
restart: "no"
`
type TxGenOption struct {
TxGenThreadSize int
TxGenDuration string
TxGenConnSize int
TxGenRate int
}