ReportJSON
This commit is contained in:
@@ -1,35 +1,36 @@
|
||||
package vegeta
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
"time"
|
||||
)
|
||||
|
||||
// Metrics holds the stats computed out of a slice of Results
|
||||
// that is used for some of the Reporters
|
||||
type Metrics struct {
|
||||
TotalRequests uint64 `json:"total_requests"`
|
||||
TotalTiming time.Duration `json:"total_timing"`
|
||||
MeanTiming time.Duration `json:"mean_timing"`
|
||||
TotalBytesIn uint64 `json:"total_bytes_in"`
|
||||
MeanBytesIn float64 `json:"mean_bytes_in"`
|
||||
TotalBytesOut uint64 `json:"total_bytes_out"`
|
||||
MeanBytesOut float64 `json:"mean_bytes_out"`
|
||||
TotalSuccess uint64 `json:"total_success"`
|
||||
MeanSuccess float64 `json:"mean_success"`
|
||||
StatusCodes map[uint16]uint64 `json:"status_codes"`
|
||||
Errors []string `json:"errors"`
|
||||
TotalRequests uint64 `json:"total_requests"`
|
||||
TotalTiming time.Duration `json:"total_timing"`
|
||||
MeanTiming time.Duration `json:"mean_timing"`
|
||||
TotalBytesIn uint64 `json:"total_bytes_in"`
|
||||
MeanBytesIn float64 `json:"mean_bytes_in"`
|
||||
TotalBytesOut uint64 `json:"total_bytes_out"`
|
||||
MeanBytesOut float64 `json:"mean_bytes_out"`
|
||||
TotalSuccess uint64 `json:"total_success"`
|
||||
MeanSuccess float64 `json:"mean_success"`
|
||||
StatusCodes map[string]int `json:"status_codes"`
|
||||
Errors []string `json:"errors"`
|
||||
}
|
||||
|
||||
// NewMetrics computes and returns a Metrics struct out of a slice of Results
|
||||
func NewMetrics(results []Result) *Metrics {
|
||||
m := &Metrics{
|
||||
TotalRequests: uint64(len(results)),
|
||||
StatusCodes: map[uint16]uint64{},
|
||||
StatusCodes: map[string]int{},
|
||||
}
|
||||
errorSet := map[string]struct{}{}
|
||||
|
||||
for _, result := range results {
|
||||
m.StatusCodes[result.Code]++
|
||||
m.StatusCodes[strconv.Itoa(int(result.Code))]++
|
||||
m.TotalTiming += result.Timing
|
||||
m.TotalBytesOut += result.BytesOut
|
||||
m.TotalBytesIn += result.BytesIn
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"code.google.com/p/plotinum/plotutil"
|
||||
"code.google.com/p/plotinum/vg"
|
||||
"code.google.com/p/plotinum/vg/vgsvg"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"text/tabwriter"
|
||||
@@ -41,6 +42,11 @@ func ReportText(results []Result, out io.Writer) error {
|
||||
return w.Flush()
|
||||
}
|
||||
|
||||
// ReportJSON writes a computed Metrics struct to out as JSON
|
||||
func ReportJSON(results []Result, out io.Writer) error {
|
||||
return json.NewEncoder(out).Encode(NewMetrics(results))
|
||||
}
|
||||
|
||||
// ReportTimingsPlot builds up a plot of the response times of the requests
|
||||
// in SVG format and writes it to out
|
||||
func ReportTimingsPlot(results []Result, out io.Writer) error {
|
||||
|
||||
Reference in New Issue
Block a user