Commit 1e31f279 authored by jingbo.wang's avatar jingbo.wang

临时

parent 9c5806e6
package report_form
import (
"fmt"
"git.quantgroup.cn/DevOps/enoch/pkg/glog"
"time"
)
func Run() {
now := time.Now()
startTime := now.Add(-1 * time.Duration(now.Hour()) * time.Hour)
startTime = startTime.Add(-1 * time.Duration(now.Minute()) * time.Minute)
startTime = startTime.Add(-1 * time.Duration(now.Second()) * time.Second)
startTime = startTime.Add(-1 * time.Duration(now.Nanosecond()))
startTime = startTime.AddDate(0, 0, -7)
endTime := startTime.AddDate(0, 0, 7)
glog.Info("startTime:", startTime.UnixNano(), " endTime:", endTime.UnixNano())
sm := NewServiceMap(startTime, endTime)
fmt.Println(sm.GetCount())
/*
t.Log("访问量:", sm.GetCount())
t.Log("总访问时间:", sm.GetSumDuration())
t.Log("总平均访问时间:", sm.GetAverageDuration())
t.Log("------------------median-------------------")
medianList := sm.GetMedianDurationPathList()
t.Log("服务数量:", len(medianList))
for _, m := range medianList {
t.Log(m.GetMedianDuration(), m.GetServiceName(), m.GetPath(), m.GetCount())
}
t.Log("------------------average------------------")
averageList := sm.GetAverageDurationPathList()
t.Log("服务数量:", len(averageList))
for _, m := range averageList {
t.Log(m.GetAverageDuration(), m.GetServiceName(), m.GetPath(), m.GetCount())
}
t.Log("------------------max----------------------")
maxList := sm.GetMaxDurationTracePointList()
t.Log("服务数量:", len(maxList))
for _, m := range maxList {
t.Log(m.Duration, m.ServiceName, m.Path, m.Timestamp, m.TraceId)
}
*/
}
package report_form
import "testing"
func TestRun(t *testing.T) {
Run()
}
...@@ -7,6 +7,10 @@ import ( ...@@ -7,6 +7,10 @@ import (
"time" "time"
) )
const (
MinCount = 64
)
type Service struct { type Service struct {
name string //服务名称 name string //服务名称
startTime time.Time //开始时间 startTime time.Time //开始时间
...@@ -115,25 +119,24 @@ func (s *Service) initDuration() { ...@@ -115,25 +119,24 @@ func (s *Service) initDuration() {
} }
s.averageDuration = s.sumDuration / time.Duration(s.count) s.averageDuration = s.sumDuration / time.Duration(s.count)
if len(s.pathMap) != 0 { medianMax := time.Duration(-99999)
medianMax := time.Duration(-99999) averageMax := time.Duration(-99999)
averageMax := time.Duration(-99999) maxDuration := time.Duration(-99999)
maxDuration := time.Duration(-99999)
for _, pathObj := range s.pathMap { for _, pathObj := range s.pathMap {
if pathObj.GetMedianDuration() > medianMax { if pathObj.GetCount() > MinCount && pathObj.GetMedianDuration() > medianMax {
s.maxMedianPath = pathObj s.maxMedianPath = pathObj
medianMax = pathObj.GetMedianDuration() medianMax = pathObj.GetMedianDuration()
} }
if pathObj.GetAverageDuration() > averageMax { if pathObj.GetCount() > MinCount && pathObj.GetAverageDuration() > averageMax {
s.maxAveragePath = pathObj s.maxAveragePath = pathObj
averageMax = pathObj.GetAverageDuration() averageMax = pathObj.GetAverageDuration()
} }
point := pathObj.GetMaxDurationTracePoint() point := pathObj.GetMaxDurationTracePoint()
if point.Duration > maxDuration { if point.Duration > maxDuration {
s.maxDurationTracePoint = &point s.maxDurationTracePoint = &point
maxDuration = point.Duration maxDuration = point.Duration
}
} }
} }
} }
......
...@@ -6,7 +6,7 @@ import ( ...@@ -6,7 +6,7 @@ import (
) )
func TestNewServiceMap(t *testing.T) { func TestNewServiceMap(t *testing.T) {
sm := NewServiceMap(time.Now().Add(time.Hour*24*-1), time.Now()) sm := NewServiceMap(time.Now().Add(time.Hour*24*-7), time.Now())
t.Log("访问量:", sm.GetCount()) t.Log("访问量:", sm.GetCount())
t.Log("总访问时间:", sm.GetSumDuration()) t.Log("总访问时间:", sm.GetSumDuration())
...@@ -15,13 +15,13 @@ func TestNewServiceMap(t *testing.T) { ...@@ -15,13 +15,13 @@ func TestNewServiceMap(t *testing.T) {
medianList := sm.GetMedianDurationPathList() medianList := sm.GetMedianDurationPathList()
t.Log("服务数量:", len(medianList)) t.Log("服务数量:", len(medianList))
for _, m := range medianList { for _, m := range medianList {
t.Log(m.GetMedianDuration(), m.GetServiceName(), m.GetPath()) t.Log(m.GetMedianDuration(), m.GetServiceName(), m.GetPath(), m.GetCount())
} }
t.Log("------------------average------------------") t.Log("------------------average------------------")
averageList := sm.GetAverageDurationPathList() averageList := sm.GetAverageDurationPathList()
t.Log("服务数量:", len(averageList)) t.Log("服务数量:", len(averageList))
for _, m := range averageList { for _, m := range averageList {
t.Log(m.GetAverageDuration(), m.GetServiceName(), m.GetPath()) t.Log(m.GetAverageDuration(), m.GetServiceName(), m.GetPath(), m.GetCount())
} }
t.Log("------------------max----------------------") t.Log("------------------max----------------------")
maxList := sm.GetMaxDurationTracePointList() maxList := sm.GetMaxDurationTracePointList()
......
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