forked from rakutentech/shibuya
-
Notifications
You must be signed in to change notification settings - Fork 0
/
jmeter.go
59 lines (53 loc) · 1.24 KB
/
jmeter.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
package controller
import (
"strconv"
"strings"
"github.com/harpratap/shibuya/shibuya/config"
)
type jmeterEngine struct {
*baseEngine
}
func NewJmeterEngine(be *baseEngine) *jmeterEngine {
be.ExecutorContainer = config.SC.ExecutorConfig.JmeterContainer.ExecutorContainer
e := &jmeterEngine{be}
return e
}
func (je *jmeterEngine) readMetrics() chan *shibuyaMetric {
ch := make(chan *shibuyaMetric)
go func() {
outer:
for {
select {
case ev, ok := <-je.stream.Events:
if !ok {
break outer
}
raw := ev.Data()
line := strings.Split(raw, "|")
label := line[2]
status := line[3]
threads, _ := strconv.ParseFloat(line[9], 64)
latency, err := strconv.ParseFloat(line[10], 64)
if err != nil {
continue outer // no csv headers
}
ch <- &shibuyaMetric{
threads: threads,
label: label,
status: status,
latency: latency,
collectionID: strconv.FormatInt(je.collectionID, 10),
planID: strconv.FormatInt(je.planID, 10),
engineID: strconv.FormatInt(int64(je.ID), 10),
runID: strconv.FormatInt(je.runID, 10),
}
case _, ok := <-je.stream.Errors:
if !ok {
break outer
}
}
}
close(ch)
}()
return ch
}