This repository has been archived by the owner on May 21, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 15
/
handler.go
103 lines (96 loc) · 3.38 KB
/
handler.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
package ultron
import (
"context"
"encoding/json"
"fmt"
"io"
"strconv"
"github.com/olekukonko/tablewriter"
"github.com/wosai/ultron/v2/pkg/statistics"
)
func printReportToConsole(output io.Writer) ReportHandleFunc {
return func(ctx context.Context, report statistics.SummaryReport) {
table := tablewriter.NewWriter(output)
header := []string{"Attacker", "Min", "P50", "P60", "P70", "P80", "P90", "P95", "P97", "P98", "P99", "Max", "Avg", "Requests", "Failures", "TPS"}
table.SetHeader(header)
table.SetHeaderColor(
tablewriter.Colors{tablewriter.Bold, tablewriter.FgBlueColor},
tablewriter.Colors{tablewriter.Bold, tablewriter.FgGreenColor},
tablewriter.Colors{tablewriter.Bold, tablewriter.FgGreenColor},
tablewriter.Colors{tablewriter.Bold, tablewriter.FgGreenColor},
tablewriter.Colors{tablewriter.Bold, tablewriter.FgGreenColor},
tablewriter.Colors{tablewriter.Bold, tablewriter.FgGreenColor},
tablewriter.Colors{tablewriter.Bold, tablewriter.FgGreenColor},
tablewriter.Colors{tablewriter.Bold, tablewriter.FgRedColor},
tablewriter.Colors{tablewriter.Bold, tablewriter.FgRedColor},
tablewriter.Colors{tablewriter.Bold, tablewriter.FgRedColor},
tablewriter.Colors{tablewriter.Bold, tablewriter.FgRedColor},
tablewriter.Colors{tablewriter.Bold, tablewriter.FgRedColor},
tablewriter.Colors{tablewriter.Bold, tablewriter.FgBlueColor},
tablewriter.Colors{tablewriter.Bold, tablewriter.BgGreenColor},
tablewriter.Colors{tablewriter.Bold, tablewriter.BgRedColor},
tablewriter.Colors{tablewriter.Bold, tablewriter.BgCyanColor},
)
footer := make([]string, 16)
if report.FullHistory {
footer[11] = "Full History"
}
footer[12] = "Total"
footer[13] = strconv.FormatUint(report.TotalRequests, 10)
footer[14] = strconv.FormatUint(report.TotalFailures, 10)
footer[15] = strconv.FormatFloat(report.TotalTPS, 'f', 2, 64)
table.SetFooter(footer)
table.SetFooterColor(
tablewriter.Colors{},
tablewriter.Colors{},
tablewriter.Colors{},
tablewriter.Colors{},
tablewriter.Colors{},
tablewriter.Colors{},
tablewriter.Colors{},
tablewriter.Colors{},
tablewriter.Colors{},
tablewriter.Colors{},
tablewriter.Colors{},
tablewriter.Colors{tablewriter.Bold, tablewriter.FgRedColor},
tablewriter.Colors{tablewriter.Bold, tablewriter.BgBlueColor},
tablewriter.Colors{},
tablewriter.Colors{},
tablewriter.Colors{},
)
table.SetBorder(false)
table.SetAlignment(tablewriter.ALIGN_CENTER)
for _, rpt := range report.Reports {
cells := []string{
rpt.Name,
rpt.Min.String(),
rpt.Distributions["0.50"].String(),
rpt.Distributions["0.60"].String(),
rpt.Distributions["0.70"].String(),
rpt.Distributions["0.80"].String(),
rpt.Distributions["0.90"].String(),
rpt.Distributions["0.95"].String(),
rpt.Distributions["0.97"].String(),
rpt.Distributions["0.98"].String(),
rpt.Distributions["0.99"].String(),
rpt.Max.String(),
rpt.Average.String(),
strconv.FormatUint(rpt.Requests, 10),
strconv.FormatUint(rpt.Failures, 10),
strconv.FormatFloat(rpt.TPS, 'f', 2, 64),
}
table.Append(cells)
}
table.Render()
fmt.Fprintln(output, "")
}
}
func printJsonReport(out io.Writer) ReportHandleFunc {
return func(c context.Context, sr statistics.SummaryReport) {
if !sr.FullHistory {
return
}
data, _ := json.MarshalIndent(sr, "", " ")
fmt.Fprint(out, string(data))
}
}