From 198e6648c1c9540eaae406e25e576da90434e21c Mon Sep 17 00:00:00 2001 From: Bojan Date: Tue, 10 Jul 2018 20:53:26 -0300 Subject: [PATCH] Add HTML output format (#18) * adding html output * [skip ci] more html output * [skip ci] more html output * html output * update readme and certs --- README.md | 5 + cmd/grpcannon/main.go | 1 + printer/printer.go | 370 +++++++++++++++++++++++++++++++++++++++++ testdata/localhost.crt | 28 ++-- testdata/localhost.key | 52 +++--- 5 files changed, 416 insertions(+), 40 deletions(-) diff --git a/README.md b/README.md index 93cea0f0..ea222c22 100644 --- a/README.md +++ b/README.md @@ -53,6 +53,7 @@ Options: "csv" outputs the response metrics in comma-separated values format. "json" outputs the metrics report in JSON format. "pretty" outputs the metrics report in pretty JSON format. + "html" outputs the metrics report as HTML. -i Comma separated list of proto import paths. The current working directory and the directory of the protocol buffer file are automatically added to the import list. @@ -186,6 +187,10 @@ duration (ms),status,error ... ``` +HTML output can be generated using `html` as format in the `-O` option. See [sample output](http://bojand.github.io/sample.html). + +Using `-O json` outputs JSON data, and `-O pretty` outputs JSON in pretty format. + ## Credit Icon made by Freepik from www.flaticon.com is licensed by CC 3.0 BY diff --git a/cmd/grpcannon/main.go b/cmd/grpcannon/main.go index 809e5f02..e68d2c23 100644 --- a/cmd/grpcannon/main.go +++ b/cmd/grpcannon/main.go @@ -85,6 +85,7 @@ Options: "csv" outputs the response metrics in comma-separated values format. "json" outputs the metrics report in JSON format. "pretty" outputs the metrics report in pretty JSON format. + "html" outputs the metrics report as HTML. -i Comma separated list of proto import paths. The current working directory and the directory of the protocol buffer file are automatically added to the import list. diff --git a/printer/printer.go b/printer/printer.go index e9d58056..1fe37866 100644 --- a/printer/printer.go +++ b/printer/printer.go @@ -60,6 +60,15 @@ func (rp *ReportPrinter) Print(format string) { } rp.printf(string(rep)) + case "html": + buf := &bytes.Buffer{} + templ := template.Must(template.New("tmpl").Funcs(tmplFuncMap).Parse(htmlTmpl)) + if err := templ.Execute(buf, *rp.Report); err != nil { + log.Println("error:", err.Error()) + return + } + + rp.printf(buf.String()) } } @@ -72,6 +81,8 @@ var tmplFuncMap = template.FuncMap{ "formatSeconds": formatSeconds, "histogram": histogram, "jsonify": jsonify, + "formatMark": formatMarkMs, + "formatPercent": formatPercent, } func jsonify(v interface{}) string { @@ -87,6 +98,11 @@ func formatSeconds(duration float64) string { return fmt.Sprintf("%4.2f", duration) } +func formatPercent(num int, total uint64) string { + p := float64(num) / float64(total) + return fmt.Sprintf("%.2f", p*100) +} + func histogram(buckets []grpcannon.Bucket) string { max := 0 for _, b := range buckets { @@ -106,6 +122,10 @@ func histogram(buckets []grpcannon.Bucket) string { return res.String() } +func formatMarkMs(m float64) string { + return fmt.Sprintf("'%4.3f ms'", m*1000) +} + var ( defaultTmpl = ` Summary: @@ -129,5 +149,355 @@ Status code distribution:{{ range $code, $num := .StatusCodeDist }} csvTmpl = ` duration (ms),status,error{{ range $i, $v := .Details }} {{ formatMilli .Latency.Seconds }},{{ .Status }},{{ .Error }}{{ end }} +` + + htmlTmpl = ` + + + + + + Results + + + + + + + + + + + +
+ + + +
+
+
+
+ +

Summary

+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + +
Count{{ .Count }}
Total{{ formatMilli .Total.Seconds }} ms
Slowest{{ formatMilli .Slowest.Seconds }} ms
Fastest{{ formatMilli .Fastest.Seconds }} ms
Average{{ formatMilli .Average.Seconds }} ms
Requests / sec{{ formatSeconds .Rps }}
+
+
+
+
+ +
+
+
+ +

Historam

+
+

+

+

+
+
+ +
+
+
+ +

Latency distribution

+
+ + + + {{ range .LatencyDistribution }} + + {{ end }} + + + + + {{ range .LatencyDistribution }} + + {{ end }} + + +
{{ .Percentage }} %%
{{ formatMilli .Latency.Seconds }} ms
+
+
+ +
+
+
+
+
+ +

Status distribution

+
+ + + + + + + + + + {{ range $code, $num := .StatusCodeDist }} + + + + + + {{ end }} + +
StatusCount%% of Total
{{ $code }}{{ $num }}{{ formatPercent $num $.Count }} %%
+
+
+
+
+ + {{ if gt (len .ErrorDist) 0 }} + +
+
+
+
+
+ +

Errors

+
+ + + + + + + + + + {{ range $err, $num := .ErrorDist }} + + + + + + {{ end }} + +
ErrorCount%% of Total
{{ $err }}{{ $num }}{{ formatPercent $num $.Count }} %%
+
+
+
+
+ + {{ end }} + +
+
+
+
+
+ +

Data

+
+ + JSON + CSV +
+
+
+
+ +
+
+
+

+ Generated by ghz +

+ +
+
+ +
+ + + + + + + + ` ) diff --git a/testdata/localhost.crt b/testdata/localhost.crt index 478d2248..bb1d4fc8 100644 --- a/testdata/localhost.crt +++ b/testdata/localhost.crt @@ -1,18 +1,18 @@ -----BEGIN CERTIFICATE----- -MIIC5TCCAc2gAwIBAgIJAJFwlruqLNgaMA0GCSqGSIb3DQEBCwUAMBQxEjAQBgNV -BAMMCWxvY2FsaG9zdDAeFw0xODA2MDExNjA1NDNaFw0xODA3MDExNjA1NDNaMBQx +MIIC5TCCAc2gAwIBAgIJAPMeFjozN41RMA0GCSqGSIb3DQEBCwUAMBQxEjAQBgNV +BAMMCWxvY2FsaG9zdDAeFw0xODA3MTAyMzMyNTNaFw0xODA4MDkyMzMyNTNaMBQx EjAQBgNVBAMMCWxvY2FsaG9zdDCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoC -ggEBALQ1gPZBLD2D4HBveN4eRzal1r8lX4AQSq9h4ofcMo/0sqz7yEQ3zH41Ff+U -KyeBSpXQ6eHtQNiJAATFNPzmHtCbS/YsE18+Msab+Qz0Bgk3pCM97k7japl6Hzag -83C/c2U1Wr3i5otCUQhk+pY2zWjh07gRZWmkp10Ijapxf7mQwC3u2vguzfXEE9co -BS2wyRiJxbwN3DIhW7fTZfoOgfnEGktrTF+hlO8YPNfodZum0jwrlv0hAwYfDiIJ -yQmNMbBLAcZIeH/ZKXEKQkFFKYfxYVMM9Hf4B2XOJ8z7M5o0R+l059RHqric6/c1 -9XPvfDvWSIijI5HgymNAUZmFT+ECAwEAAaM6MDgwFAYDVR0RBA0wC4IJbG9jYWxo +ggEBALVt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znaO/rTKH/9EmZ62RXXrtSrLcOEQxG3rXpufIvR0sJudQH97gU +GRgmIuMq+utwhFHP1+rZj7Kwh+u+anN4Lg== -----END CERTIFICATE----- diff --git a/testdata/localhost.key b/testdata/localhost.key index 898e7cd7..ee8aeae4 100644 --- a/testdata/localhost.key +++ b/testdata/localhost.key @@ -1,28 +1,28 @@ -----BEGIN PRIVATE KEY----- -MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQC0NYD2QSw9g+Bw -b3jeHkc2pda/JV+AEEqvYeKH3DKP9LKs+8hEN8x+NRX/lCsngUqV0Onh7UDYiQAE -xTT85h7Qm0v2LBNfPjLGm/kM9AYJN6QjPe5O42qZeh82oPNwv3NlNVq94uaLQlEI -ZPqWNs1o4dO4EWVppKddCI2qcX+5kMAt7tr4Ls31xBPXKAUtsMkYicW8DdwyIVu3 -02X6DoH5xBpLa0xfoZTvGDzX6HWbptI8K5b9IQMGHw4iCckJjTGwSwHGSHh/2Slx -CkJBRSmH8WFTDPR3+AdlzifM+zOaNEfpdOfUR6q4nOv3NfVz73w71kiIoyOR4Mpj -QFGZhU/hAgMBAAECggEBAJFEqCbatq0IB/7a/VYglkuJOClyGSAFAg+LGq9mZCQD -n50ugmvrhx8d8BPM/1SjNtq6RC9pr+Jd3fP6fRJ49tI2ve897IfUfd34kbVNaSg5 -AEmgfOB/FsmN1meVK2jyDDXD4tg7dpk/5k6cCBzbJI6trJwu+c9FedzXLkv9nnaY -zNKkVfRFFgS9f0e48ASDSDERYzbPEsO6OXkZHZIFfXcE0I297LtwzeYQN0ScGQ98 -3CC/lAipClpMsENfhEH5SIbLT6I9IXSzT+yDiA+Q6PApzuXQd0d+Y3ADns7rn8Ie -QTGNRMOhFKSqciOdW/fL+gHlyoqcWU5XCP2wfTVnrqECgYEA26HzsdHgRKnBe4Cf -GwEw6t+nA2Mf04AXpfJDVy5UEMupiPOZjZi/jPO539BKl1sks/nYT2oFfL6f+1PP -vH1G/NMTJVR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