Skip to content

Commit

Permalink
boolean flag to enable raw per-request metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
rogerwelin committed Nov 1, 2022
1 parent 9a33d03 commit c74f564
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 0 deletions.
6 changes: 6 additions & 0 deletions cmd/cassowary/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ func validateCLI(c *cli.Context) error {
Boxplot: c.Bool("boxplot"),
Histogram: c.Bool("histogram"),
ExportMetrics: c.Bool("json-metrics"),
RawOutput: c.Bool("raw-output"),
ExportMetricsFile: c.String("json-metrics-file"),
DisableKeepAlive: c.Bool("disable-keep-alive"),
Timeout: c.Int("timeout"),
Expand Down Expand Up @@ -279,6 +280,11 @@ func runCLI(args []string) {
Aliases: []string{"cloudwatch"},
Usage: "enable to send metrics to AWS Cloudwatch",
},
&cli.BoolFlag{
Name: "R",
Aliases: []string{"raw-output"},
Usage: "enable to export raw per-request metrics",
},
&cli.BoolFlag{
Name: "F",
Aliases: []string{"json-metrics"},
Expand Down
24 changes: 24 additions & 0 deletions pkg/client/helpers.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package client

import (
"fmt"
"net/url"
"reflect"
"strconv"
"strings"
)
Expand Down Expand Up @@ -56,3 +58,25 @@ func generateSuffixes(src []string, length int) []string {
}
return urls
}

func toSlice(in durationMetrics) []string {
s := []string{
fmt.Sprintf("%f", in.DNSLookup),
fmt.Sprintf("%f", in.TCPConn),
fmt.Sprintf("%f", in.TLSHandshake),
fmt.Sprintf("%f", in.ServerProcessing),
fmt.Sprintf("%f", in.ContentTransfer),
strconv.Itoa(in.StatusCode),
fmt.Sprintf("%f", in.TotalDuration),
}
return s
}

func structNames(a *durationMetrics) []string {
names := []string{}
val := reflect.ValueOf(a).Elem()
for i := 0; i < val.NumField(); i++ {
names = append(names, val.Type().Field(i).Name)
}
return names
}
19 changes: 19 additions & 0 deletions pkg/client/load.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ import (
"bytes"
"context"
"crypto/tls"
"encoding/csv"
"fmt"
"io"
"io/ioutil"
"log"
"net/http"
"net/http/httptrace"
"os"
"sync"
"time"

Expand Down Expand Up @@ -243,7 +245,22 @@ func (c *Cassowary) Coordinate() (ResultMetrics, error) {
fmt.Println(end)
}

var w *csv.Writer

if c.RawOutput {
csvFile, _ := os.Create("raw.csv")
w = csv.NewWriter(csvFile)
headerInfo := structNames(&durationMetrics{})
w.Write(headerInfo)
defer csvFile.Close()
defer w.Flush()
}

for item := range channel {
if c.RawOutput {
itemSlice := toSlice(item)
w.Write(itemSlice)
}
if item.DNSLookup != 0 {
dnsDur = append(dnsDur, item.DNSLookup)
}
Expand Down Expand Up @@ -310,13 +327,15 @@ func (c *Cassowary) Coordinate() (ResultMetrics, error) {
if c.Histogram {
err := c.PlotHistogram(totalDur)
if err != nil {
fmt.Println(err)
}
}

// output boxplot
if c.Boxplot {
err := c.PlotBoxplot(totalDur)
if err != nil {
fmt.Println(err)
}
}
return outPut, nil
Expand Down
1 change: 1 addition & 0 deletions pkg/client/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
type Cassowary struct {
FileMode bool
IsTLS bool
RawOutput bool
BaseURL string
ConcurrencyLevel int
Requests int
Expand Down

0 comments on commit c74f564

Please sign in to comment.