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

添加qps数据

parent 3cb116c8
...@@ -18,7 +18,7 @@ func SendEmail(title string, content string, receiver ...string) { ...@@ -18,7 +18,7 @@ func SendEmail(title string, content string, receiver ...string) {
//m.SetHeader("To", []string{receiver}) //m.SetHeader("To", []string{receiver})
m.SetHeader("To", receiver...) m.SetHeader("To", receiver...)
m.SetHeader("Subject", title) m.SetHeader("Subject", title)
m.SetBody("text/html", "<pre>"+content+"</pre>") m.SetBody("text/html", "<div><pre>"+content+"</pre></div>")
userName := "program@quantgroup.cn" userName := "program@quantgroup.cn"
pwd := "Fuck147999!!!" pwd := "Fuck147999!!!"
......
...@@ -24,6 +24,7 @@ type Path struct { ...@@ -24,6 +24,7 @@ type Path struct {
averageDuration time.Duration //平均响应时间 averageDuration time.Duration //平均响应时间
sumDuration time.Duration //总响应时间 sumDuration time.Duration //总响应时间
medianDuration time.Duration //中位响应时间 medianDuration time.Duration //中位响应时间
qps int //每秒的访问量
variance float64 //标准差 variance float64 //标准差
maxDurationTracePoint TracePoint //最大响应时间的TracePoint maxDurationTracePoint TracePoint //最大响应时间的TracePoint
} }
...@@ -43,9 +44,18 @@ func NewPath(serviceName string, path string, startTime time.Time, endTime time. ...@@ -43,9 +44,18 @@ func NewPath(serviceName string, path string, startTime time.Time, endTime time.
rtn.initAverageDuration() rtn.initAverageDuration()
rtn.initMedianDuration() rtn.initMedianDuration()
rtn.initMaxDurationTracePoint() rtn.initMaxDurationTracePoint()
rtn.initQps()
return rtn, true return rtn, true
} }
//初始化qps
func (p *Path) initQps() {
if p.startTime.Unix() >= p.endTime.Unix() {
return
}
p.qps = p.count / int(p.endTime.Sub(p.startTime).Seconds())
}
//初始化访问次数 //初始化访问次数
func (p *Path) initCount() { func (p *Path) initCount() {
const sqlGetCount = `SELECT count("traceId") AS count FROM trace_info ` + const sqlGetCount = `SELECT count("traceId") AS count FROM trace_info ` +
...@@ -188,6 +198,11 @@ func (p *Path) GetSumDuration() time.Duration { ...@@ -188,6 +198,11 @@ func (p *Path) GetSumDuration() time.Duration {
return p.sumDuration return p.sumDuration
} }
//获取qps
func (p *Path) GetQps() int {
return p.qps
}
//获取平均响应时间 //获取平均响应时间
func (p *Path) GetAverageDuration() time.Duration { func (p *Path) GetAverageDuration() time.Duration {
return p.averageDuration return p.averageDuration
......
...@@ -24,6 +24,7 @@ type Service struct { ...@@ -24,6 +24,7 @@ type Service struct {
maxMedianPath *Path //最大中位响应时间path maxMedianPath *Path //最大中位响应时间path
maxAveragePath *Path //最大平均响应时间path maxAveragePath *Path //最大平均响应时间path
maxDurationTracePoint *TracePoint //最大响应时间的tracePoint maxDurationTracePoint *TracePoint //最大响应时间的tracePoint
qps int
//node相关 //node相关
nodeMap map[string]*Node //节点列表 nodeMap map[string]*Node //节点列表
} }
...@@ -46,6 +47,7 @@ func NewService(name string, startTime time.Time, endTime time.Time) *Service { ...@@ -46,6 +47,7 @@ func NewService(name string, startTime time.Time, endTime time.Time) *Service {
endTime: endTime, endTime: endTime,
pathMap: make(map[string]*Path), pathMap: make(map[string]*Path),
nodeMap: make(map[string]*Node), nodeMap: make(map[string]*Node),
qps: 0,
} }
//初始化path //初始化path
...@@ -69,6 +71,8 @@ func NewService(name string, startTime time.Time, endTime time.Time) *Service { ...@@ -69,6 +71,8 @@ func NewService(name string, startTime time.Time, endTime time.Time) *Service {
//初始化访问时间相关的参数 //初始化访问时间相关的参数
rtn.initDuration() rtn.initDuration()
//初始化qps
rtn.initQps()
//初始化node //初始化node
nodeList := rtn.getNodeList() nodeList := rtn.getNodeList()
...@@ -80,6 +84,13 @@ func NewService(name string, startTime time.Time, endTime time.Time) *Service { ...@@ -80,6 +84,13 @@ func NewService(name string, startTime time.Time, endTime time.Time) *Service {
return &rtn return &rtn
} }
//初始化qps
func (s *Service) initQps() {
for _, p := range s.pathMap {
s.qps += p.GetQps()
}
}
//获取服务名称 //获取服务名称
func (s *Service) Name() string { func (s *Service) Name() string {
return s.name return s.name
...@@ -213,6 +224,11 @@ func (s *Service) GetAverageDurationPathList() []*Path { ...@@ -213,6 +224,11 @@ func (s *Service) GetAverageDurationPathList() []*Path {
return rtn return rtn
} }
//获取qps
func (s *Service) GetQps() int {
return s.qps
}
//获取 MedianDuration Path 排行 //获取 MedianDuration Path 排行
func (s *Service) GetMedianDurationPathList() []*Path { func (s *Service) GetMedianDurationPathList() []*Path {
rtn := make([]*Path, 0) rtn := make([]*Path, 0)
...@@ -231,7 +247,6 @@ func (s *Service) GetMedianDurationPathList() []*Path { ...@@ -231,7 +247,6 @@ func (s *Service) GetMedianDurationPathList() []*Path {
return rtn return rtn
} }
//获取 MaxDuration Path 排行 //获取 MaxDuration Path 排行
func (s *Service) GetMaxDurationPathList() []*Path { func (s *Service) GetMaxDurationPathList() []*Path {
rtn := make([]*Path, 0) rtn := make([]*Path, 0)
......
...@@ -143,6 +143,15 @@ func (sm *ServiceMap) GetMaxDiskServiceList() []*Service { ...@@ -143,6 +143,15 @@ func (sm *ServiceMap) GetMaxDiskServiceList() []*Service {
return rtn return rtn
} }
//获取qps
func (sm *ServiceMap) GetQps() int {
rtn := 0
for _, s := range sm.serviceMap {
rtn += s.GetQps()
}
return rtn
}
//服务平均响应时间排行 //服务平均响应时间排行
func (sm *ServiceMap) GetAverageDurationServiceList() []*Service { func (sm *ServiceMap) GetAverageDurationServiceList() []*Service {
rtn := make([]*Service, 0) rtn := make([]*Service, 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