mirror of
https://github.com/httprunner/httprunner.git
synced 2026-09-05 07:26:55 +08:00
fix: getCurrentRps
This commit is contained in:
+10
-14
@@ -81,12 +81,8 @@ func getAvgContentLength(numRequests int64, totalContentLength int64) (avgConten
|
||||
return avgContentLength
|
||||
}
|
||||
|
||||
func getCurrentRps(numRequests int64, numReqsPerSecond map[int64]int64) (currentRps int64) {
|
||||
currentRps = int64(0)
|
||||
numReqsPerSecondLength := int64(len(numReqsPerSecond))
|
||||
if numReqsPerSecondLength != 0 {
|
||||
currentRps = numRequests / numReqsPerSecondLength
|
||||
}
|
||||
func getCurrentRps(numRequests int64) (currentRps float64) {
|
||||
currentRps = float64(numRequests) / float64(reportStatsInterval/time.Second)
|
||||
return currentRps
|
||||
}
|
||||
|
||||
@@ -125,7 +121,7 @@ func (o *ConsoleOutput) OnEvent(data map[string]interface{}) {
|
||||
}
|
||||
|
||||
currentTime := time.Now()
|
||||
println(fmt.Sprintf("Current time: %s, Users: %d, State: %d, Total RPS: %d, Total Fail Ratio: %.1f%%",
|
||||
println(fmt.Sprintf("Current time: %s, Users: %d, State: %d, Total RPS: %.1f, Total Fail Ratio: %.1f%%",
|
||||
currentTime.Format("2006/01/02 15:04:05"), output.UserCount, output.State, output.TotalRPS, output.TotalFailRatio*100))
|
||||
println(fmt.Sprintf("Accumulated Transactions: %d Passed, %d Failed",
|
||||
output.TransactionsPassed, output.TransactionsFailed))
|
||||
@@ -143,7 +139,7 @@ func (o *ConsoleOutput) OnEvent(data map[string]interface{}) {
|
||||
row[6] = strconv.FormatInt(stat.MinResponseTime, 10)
|
||||
row[7] = strconv.FormatInt(stat.MaxResponseTime, 10)
|
||||
row[8] = strconv.FormatInt(stat.avgContentLength, 10)
|
||||
row[9] = strconv.FormatInt(stat.currentRps, 10)
|
||||
row[9] = strconv.FormatFloat(stat.currentRps, 'f', 2, 64)
|
||||
row[10] = strconv.FormatInt(stat.currentFailPerSec, 10)
|
||||
table.Append(row)
|
||||
}
|
||||
@@ -157,7 +153,7 @@ type statsEntryOutput struct {
|
||||
medianResponseTime int64 // median response time
|
||||
avgResponseTime float64 // average response time, round float to 2 decimal places
|
||||
avgContentLength int64 // average content size
|
||||
currentRps int64 // # reqs/sec
|
||||
currentRps float64 // # reqs/sec
|
||||
currentFailPerSec int64 // # fails/sec
|
||||
}
|
||||
|
||||
@@ -167,7 +163,7 @@ type dataOutput struct {
|
||||
TotalStats *statsEntryOutput `json:"stats_total"`
|
||||
TransactionsPassed int64 `json:"transactions_passed"`
|
||||
TransactionsFailed int64 `json:"transactions_failed"`
|
||||
TotalRPS int64 `json:"total_rps"`
|
||||
TotalRPS float64 `json:"total_rps"`
|
||||
TotalFailRatio float64 `json:"total_fail_ratio"`
|
||||
Stats []*statsEntryOutput `json:"stats"`
|
||||
Errors map[string]map[string]interface{} `json:"errors"`
|
||||
@@ -210,7 +206,7 @@ func convertData(data map[string]interface{}) (output *dataOutput, err error) {
|
||||
TotalStats: entryTotalOutput,
|
||||
TransactionsPassed: transactionsPassed,
|
||||
TransactionsFailed: transactionsFailed,
|
||||
TotalRPS: getCurrentRps(entryTotalOutput.NumRequests, entryTotalOutput.NumReqsPerSec),
|
||||
TotalRPS: getCurrentRps(entryTotalOutput.NumRequests),
|
||||
TotalFailRatio: getTotalFailRatio(entryTotalOutput.NumRequests, entryTotalOutput.NumFailures),
|
||||
Stats: make([]*statsEntryOutput, 0, len(stats)),
|
||||
}
|
||||
@@ -246,7 +242,7 @@ func deserializeStatsEntry(stat interface{}) (entryOutput *statsEntryOutput, err
|
||||
medianResponseTime: getMedianResponseTime(numRequests, entry.ResponseTimes),
|
||||
avgResponseTime: getAvgResponseTime(numRequests, entry.TotalResponseTime),
|
||||
avgContentLength: getAvgContentLength(numRequests, entry.TotalContentLength),
|
||||
currentRps: getCurrentRps(numRequests, entry.NumReqsPerSec),
|
||||
currentRps: getCurrentRps(numRequests),
|
||||
currentFailPerSec: getCurrentFailPerSec(entry.NumFailures, entry.NumFailPerSec),
|
||||
}
|
||||
return
|
||||
@@ -418,7 +414,7 @@ func (o *PrometheusPusherOutput) OnEvent(data map[string]interface{}) {
|
||||
gaugeState.Set(float64(output.State))
|
||||
|
||||
// rps in total
|
||||
gaugeTotalRPS.Set(float64(output.TotalRPS))
|
||||
gaugeTotalRPS.Set(output.TotalRPS)
|
||||
|
||||
// failure ratio in total
|
||||
gaugeTotalFailRatio.Set(output.TotalFailRatio)
|
||||
@@ -437,7 +433,7 @@ func (o *PrometheusPusherOutput) OnEvent(data map[string]interface{}) {
|
||||
gaugeMinResponseTime.WithLabelValues(method, name).Set(float64(stat.MinResponseTime))
|
||||
gaugeMaxResponseTime.WithLabelValues(method, name).Set(float64(stat.MaxResponseTime))
|
||||
gaugeAverageContentLength.WithLabelValues(method, name).Set(float64(stat.avgContentLength))
|
||||
gaugeCurrentRPS.WithLabelValues(method, name).Set(float64(stat.currentRps))
|
||||
gaugeCurrentRPS.WithLabelValues(method, name).Set(stat.currentRps)
|
||||
gaugeCurrentFailPerSec.WithLabelValues(method, name).Set(float64(stat.currentFailPerSec))
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user