Commit 463e2b06 authored by jingbo.wang's avatar jingbo.wang

总表完成

parent f7a265d6
...@@ -6,7 +6,6 @@ import ( ...@@ -6,7 +6,6 @@ import (
"git.quantgroup.cn/DevOps/enoch/pkg/global" "git.quantgroup.cn/DevOps/enoch/pkg/global"
"git.quantgroup.cn/DevOps/enoch/pkg/glog" "git.quantgroup.cn/DevOps/enoch/pkg/glog"
"git.quantgroup.cn/DevOps/enoch/pkg/points" "git.quantgroup.cn/DevOps/enoch/pkg/points"
"git.quantgroup.cn/DevOps/enoch/pkg/report-form"
"github.com/Shopify/sarama" "github.com/Shopify/sarama"
_ "github.com/mkevac/debugcharts" _ "github.com/mkevac/debugcharts"
"net/http" "net/http"
...@@ -112,7 +111,7 @@ func main() { ...@@ -112,7 +111,7 @@ func main() {
dao.DbInit() dao.DbInit()
//健康状态报表 //健康状态报表
report_form.RegularReport(global.ReportFormDir) // report_form.RegularReport(global.ReportFormDir)
//TODO 告警策略 //TODO 告警策略
} }
......
...@@ -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", "<div><pre>"+content+"</pre></div>") m.SetBody("text/html", content)
userName := "program@quantgroup.cn" userName := "program@quantgroup.cn"
pwd := "Fuck147999!!!" pwd := "Fuck147999!!!"
......
...@@ -24,7 +24,7 @@ type Path struct { ...@@ -24,7 +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 //每秒的访问量 qps float64 //每秒的访问量
variance float64 //标准差 variance float64 //标准差
maxDurationTracePoint TracePoint //最大响应时间的TracePoint maxDurationTracePoint TracePoint //最大响应时间的TracePoint
} }
...@@ -53,7 +53,7 @@ func (p *Path) initQps() { ...@@ -53,7 +53,7 @@ func (p *Path) initQps() {
if p.startTime.Unix() >= p.endTime.Unix() { if p.startTime.Unix() >= p.endTime.Unix() {
return return
} }
p.qps = p.count / int(p.endTime.Sub(p.startTime).Seconds()) p.qps = float64(p.count) / p.endTime.Sub(p.startTime).Seconds()
} }
//初始化访问次数 //初始化访问次数
...@@ -193,16 +193,16 @@ func (p *Path) GetCount() int { ...@@ -193,16 +193,16 @@ func (p *Path) GetCount() int {
return p.count return p.count
} }
//获取qps
func (p *Path) GetQps() float64 {
return p.qps
}
//获取总响应时间 //获取总响应时间
func (p *Path) GetSumDuration() time.Duration { 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
......
package report_form package report_form
import ( /*
"encoding/json"
"git.quantgroup.cn/DevOps/enoch/pkg/email"
"git.quantgroup.cn/DevOps/enoch/pkg/global"
"git.quantgroup.cn/DevOps/enoch/pkg/glog"
"github.com/vrg0/go-common/util"
"io/ioutil"
"runtime/debug"
"time"
)
var ( var (
receiverList = make([]string, 0) receiverList = make([]string, 0)
serviceOwner = make(map[string][]string) serviceOwner = make(map[string][]string)
...@@ -68,7 +58,7 @@ func run(now time.Time, dir string) { ...@@ -68,7 +58,7 @@ func run(now time.Time, dir string) {
fileNamePrefix := now.Format("2006-01-02") fileNamePrefix := now.Format("2006-01-02")
//周表 //周表
if now.Weekday() == time.Monday { if now.Weekday() == time.Tuesday {
sm := GeneralTableNewSM(7) sm := GeneralTableNewSM(7)
//总表 //总表
...@@ -103,3 +93,4 @@ func run(now time.Time, dir string) { ...@@ -103,3 +93,4 @@ func run(now time.Time, dir string) {
} }
} }
} }
*/
package report_form package report_form
import "testing" /*
func TestRegularReport(t *testing.T) { func TestRegularReport(t *testing.T) {
RegularReport("/var/enoch_health_table") RegularReport("/var/enoch_health_table")
select {} select {}
} }
*/
This diff is collapsed.
...@@ -3,9 +3,15 @@ package report_form ...@@ -3,9 +3,15 @@ package report_form
import ( import (
"fmt" "fmt"
"testing" "testing"
"unicode/utf8" "time"
) )
func TestRun(t *testing.T) {
smForm := ServiceMapReportForm(time.Now().AddDate(0, 0, -10), time.Now())
fmt.Println(smForm)
}
/*
func TestRun(t *testing.T) { func TestRun(t *testing.T) {
sm := GeneralTableNewSM(7) sm := GeneralTableNewSM(7)
fmt.Println(GeneralTableRun(sm)) fmt.Println(GeneralTableRun(sm))
...@@ -19,3 +25,4 @@ func TestUtf8StringLen(t *testing.T) { ...@@ -19,3 +25,4 @@ func TestUtf8StringLen(t *testing.T) {
i += size i += size
} }
} }
*/
...@@ -24,7 +24,7 @@ type Service struct { ...@@ -24,7 +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 qps float64 //QPS
//node相关 //node相关
nodeMap map[string]*Node //节点列表 nodeMap map[string]*Node //节点列表
} }
...@@ -225,7 +225,7 @@ func (s *Service) GetAverageDurationPathList() []*Path { ...@@ -225,7 +225,7 @@ func (s *Service) GetAverageDurationPathList() []*Path {
} }
//获取qps //获取qps
func (s *Service) GetQps() int { func (s *Service) GetQps() float64 {
return s.qps return s.qps
} }
...@@ -295,18 +295,20 @@ func (s *Service) GetMaxDurationTracePoint() (*TracePoint, bool) { ...@@ -295,18 +295,20 @@ func (s *Service) GetMaxDurationTracePoint() (*TracePoint, bool) {
return s.maxDurationTracePoint, s.maxDurationTracePoint != nil return s.maxDurationTracePoint, s.maxDurationTracePoint != nil
} }
//求平均 //求最大
func (s *Service) getNodeMapValue(f func(node *Node) int) int { func (s *Service) getNodeMapValue(f func(node *Node) int) int {
if len(s.nodeMap) == 0 { if len(s.nodeMap) == 0 {
return 0 return 0
} }
sum := 0 max := 0
for _, node := range s.nodeMap { for _, node := range s.nodeMap {
sum += f(node) if f(node) > max {
max = f(node)
}
} }
return sum / len(s.nodeMap) return max
} }
func (s *Service) GetAverageCpu() int { func (s *Service) GetAverageCpu() int {
......
...@@ -126,6 +126,23 @@ func (sm *ServiceMap) GetMaxMemServiceList() []*Service { ...@@ -126,6 +126,23 @@ func (sm *ServiceMap) GetMaxMemServiceList() []*Service {
return rtn return rtn
} }
//获取平均内存使用率列表
func (sm *ServiceMap) GetAverageMemServiceList() []*Service {
rtn := make([]*Service, 0)
for _, s := range sm.serviceMap {
rtn = append(rtn, s)
}
sort.Slice(rtn, func(i, j int) bool {
if rtn[i].GetAverageMem() > rtn[j].GetAverageMem() {
return true
}
return false
})
return rtn
}
//获取峰值磁盘使用率列表 //获取峰值磁盘使用率列表
func (sm *ServiceMap) GetMaxDiskServiceList() []*Service { func (sm *ServiceMap) GetMaxDiskServiceList() []*Service {
rtn := make([]*Service, 0) rtn := make([]*Service, 0)
...@@ -144,8 +161,8 @@ func (sm *ServiceMap) GetMaxDiskServiceList() []*Service { ...@@ -144,8 +161,8 @@ func (sm *ServiceMap) GetMaxDiskServiceList() []*Service {
} }
//获取qps //获取qps
func (sm *ServiceMap) GetQps() int { func (sm *ServiceMap) GetQps() float64 {
rtn := 0 rtn := float64(0)
for _, s := range sm.serviceMap { for _, s := range sm.serviceMap {
rtn += s.GetQps() rtn += s.GetQps()
} }
...@@ -245,6 +262,11 @@ func (sm *ServiceMap) GetCount() int { ...@@ -245,6 +262,11 @@ func (sm *ServiceMap) GetCount() int {
return sum return sum
} }
//获取service map
func (sm *ServiceMap) GetServiceMap() map[string]*Service {
return sm.serviceMap
}
//获取总响应时间 //获取总响应时间
func (sm *ServiceMap) GetSumDuration() time.Duration { func (sm *ServiceMap) GetSumDuration() time.Duration {
sum := time.Duration(0) sum := time.Duration(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