11package metricsink
22
33import (
4+ "fmt"
5+ "math"
46 "runtime"
57 "runtime/pprof"
8+ "strconv"
69 "strings"
710 "time"
811
9- "fmt"
1012 "github.com/rcrowley/go-metrics"
11- "strconv"
1213)
1314
1415var threadCreateProfile = pprof .Lookup ("threadcreate" )
@@ -73,6 +74,7 @@ func (monitorData *MonitorData) getOrCreateInterfaceInfo(name string) *Interface
7374 monitorData .Interfaces = append (monitorData .Interfaces , interfaceInfo )
7475 return interfaceInfo
7576}
77+
7678func (monitorData * MonitorData ) appendInterfaceInfo (name string , i interface {}) {
7779 var interfaceInfo = monitorData .getOrCreateInterfaceInfo (getInterfaceName (name ))
7880 switch metric := i .(type ) {
@@ -87,6 +89,15 @@ func (monitorData *MonitorData) appendInterfaceInfo(name string, i interface{})
8789 case "successes" :
8890 interfaceInfo .successCount = metric .Count ()
8991 }
92+
93+ qps := (float64 (interfaceInfo .Total ) * (1 - math .Exp (- 5.0 / 60.0 / 1 )))
94+ movingAverageFor3Precision , err := strconv .ParseFloat (fmt .Sprintf ("%.3f" , qps ), 64 )
95+ if err == nil {
96+ interfaceInfo .QPS = movingAverageFor3Precision
97+ } else {
98+ interfaceInfo .QPS = 0
99+ }
100+
90101 case metrics.Timer :
91102 t := metric .Snapshot ()
92103 ps := t .Percentiles ([]float64 {0.05 , 0.25 , 0.5 , 0.75 , 0.90 , 0.99 , 0.995 })
@@ -100,12 +111,6 @@ func (monitorData *MonitorData) appendInterfaceInfo(name string, i interface{})
100111 interfaceInfo .L99 = int (ps [5 ] / float64 (time .Millisecond ))
101112 interfaceInfo .L995 = int (ps [6 ] / float64 (time .Millisecond ))
102113 interfaceInfo .Latency = int (t .Mean () / float64 (time .Millisecond ))
103- movingAverageFor3Precision , err := strconv .ParseFloat (fmt .Sprintf ("%.3f" , t .Rate1 ()), 64 )
104- if err == nil {
105- interfaceInfo .QPS = movingAverageFor3Precision
106- } else {
107- interfaceInfo .QPS = 0
108- }
109114 }
110115 }
111116 if interfaceInfo .Total == 0 {
0 commit comments