Commit 39357833 authored by jingbo.wang's avatar jingbo.wang

优化 serviceMap.maxqps

parent 57b255fc
......@@ -251,7 +251,7 @@ func (sm *ServiceMap) ReportForm(long string) string {
sm.GetSumDuration()/1e6*1e6, //精度保留到毫秒
sm.GetAverageDuration()/1e6*1e6, //精度保留到毫秒
sm.GetQps(),
hrn(sm.GetMapQps()),
hrn(sm.GetMaxQps()),
))
url := fmt.Sprintf("http://%s:%d/show/%s/%s/%s\n", global.LocalIp, global.HttpPort,
long, sm.endTime.Add(time.Hour * -24).In(cstZone).Format("2006/01/02"), "all")
......
......@@ -171,12 +171,43 @@ func (sm *ServiceMap) GetQps() float64 {
}
//获取最大qps
func (sm *ServiceMap) GetMapQps() int {
const sqlMaxQps = "SELECT max(qps) as MAXQPS FROM " +
func (sm *ServiceMap) GetMaxQps() int {
//单位秒
const lang = 3600
t := sm.endTime.Unix() - sm.startTime.Unix()
if t <= 0 {
return 0
}
//分段获取MAXQPS
start := sm.startTime
end := sm.endTime
maxList := make([]int, 0)
for start.Unix() < end.Unix() {
if start.Unix()+lang < end.Unix() {
maxList = append(maxList, sm.getMaxQps(start, end))
start.Add(time.Second * lang)
} else {
maxList = append(maxList, sm.getMaxQps(start, sm.endTime))
}
}
//取最大值
max := 0
for _, x := range maxList {
if x > max {
max = x
}
}
return max
}
func (sm *ServiceMap) getMaxQps(start time.Time, end time.Time) int {
const sqlMaxQps = "SELECT max(qps) as maxqps FROM " +
"(SELECT count(\"traceId\") AS qps FROM trace_info " +
"WHERE time >= %d AND time < %d " +
"GROUP BY time(1s));"
sql := fmt.Sprintf(sqlMaxQps, sm.startTime.UnixNano(), sm.endTime.UnixNano())
sql := fmt.Sprintf(sqlMaxQps, start.UnixNano(), end.UnixNano())
maxqps, ok := queryOneAndToInt(sql)
if !ok {
return 0
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment