Add implements the Add method of the Report interface by adding the given Result to Metrics.
(r *Result)
| 48 | // Add implements the Add method of the Report interface by adding the given |
| 49 | // Result to Metrics. |
| 50 | func (m *Metrics) Add(r *Result) { |
| 51 | m.init() |
| 52 | |
| 53 | m.Requests++ |
| 54 | m.StatusCodes[strconv.Itoa(int(r.Code))]++ |
| 55 | m.BytesOut.Total += r.BytesOut |
| 56 | m.BytesIn.Total += r.BytesIn |
| 57 | |
| 58 | m.Latencies.Add(r.Latency) |
| 59 | |
| 60 | if m.Earliest.IsZero() || m.Earliest.After(r.Timestamp) { |
| 61 | m.Earliest = r.Timestamp |
| 62 | } |
| 63 | |
| 64 | if r.Timestamp.After(m.Latest) { |
| 65 | m.Latest = r.Timestamp |
| 66 | } |
| 67 | |
| 68 | if end := r.End(); end.After(m.End) { |
| 69 | m.End = end |
| 70 | } |
| 71 | |
| 72 | if r.Code >= 200 && r.Code < 400 { |
| 73 | m.success++ |
| 74 | } |
| 75 | |
| 76 | if r.Error != "" { |
| 77 | if _, ok := m.errors[r.Error]; !ok { |
| 78 | m.errors[r.Error] = struct{}{} |
| 79 | m.Errors = append(m.Errors, r.Error) |
| 80 | } |
| 81 | } |
| 82 | |
| 83 | if m.Histogram != nil { |
| 84 | m.Histogram.Add(r) |
| 85 | } |
| 86 | } |
| 87 | |
| 88 | // Close implements the Close method of the Report interface by computing |
| 89 | // derived summary metrics which don't need to be run on every Add call. |