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

总表完成

parent f7a265d6
......@@ -6,7 +6,6 @@ import (
"git.quantgroup.cn/DevOps/enoch/pkg/global"
"git.quantgroup.cn/DevOps/enoch/pkg/glog"
"git.quantgroup.cn/DevOps/enoch/pkg/points"
"git.quantgroup.cn/DevOps/enoch/pkg/report-form"
"github.com/Shopify/sarama"
_ "github.com/mkevac/debugcharts"
"net/http"
......@@ -112,7 +111,7 @@ func main() {
dao.DbInit()
//健康状态报表
report_form.RegularReport(global.ReportFormDir)
// report_form.RegularReport(global.ReportFormDir)
//TODO 告警策略
}
......
......@@ -18,7 +18,7 @@ func SendEmail(title string, content string, receiver ...string) {
//m.SetHeader("To", []string{receiver})
m.SetHeader("To", receiver...)
m.SetHeader("Subject", title)
m.SetBody("text/html", "<div><pre>"+content+"</pre></div>")
m.SetBody("text/html", content)
userName := "program@quantgroup.cn"
pwd := "Fuck147999!!!"
......
......@@ -24,7 +24,7 @@ type Path struct {
averageDuration time.Duration //平均响应时间
sumDuration time.Duration //总响应时间
medianDuration time.Duration //中位响应时间
qps int //每秒的访问量
qps float64 //每秒的访问量
variance float64 //标准差
maxDurationTracePoint TracePoint //最大响应时间的TracePoint
}
......@@ -53,7 +53,7 @@ func (p *Path) initQps() {
if p.startTime.Unix() >= p.endTime.Unix() {
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 {
return p.count
}
//获取qps
func (p *Path) GetQps() float64 {
return p.qps
}
//获取总响应时间
func (p *Path) GetSumDuration() time.Duration {
return p.sumDuration
}
//获取qps
func (p *Path) GetQps() int {
return p.qps
}
//获取平均响应时间
func (p *Path) GetAverageDuration() time.Duration {
return p.averageDuration
......
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 (
receiverList = make([]string, 0)
serviceOwner = make(map[string][]string)
......@@ -68,7 +58,7 @@ func run(now time.Time, dir string) {
fileNamePrefix := now.Format("2006-01-02")
//周表
if now.Weekday() == time.Monday {
if now.Weekday() == time.Tuesday {
sm := GeneralTableNewSM(7)
//总表
......@@ -103,3 +93,4 @@ func run(now time.Time, dir string) {
}
}
}
*/
package report_form
import "testing"
/*
func TestRegularReport(t *testing.T) {
RegularReport("/var/enoch_health_table")
select {}
}
*/
This diff is collapsed.
......@@ -3,9 +3,15 @@ package report_form
import (
"fmt"
"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) {
sm := GeneralTableNewSM(7)
fmt.Println(GeneralTableRun(sm))
......@@ -19,3 +25,4 @@ func TestUtf8StringLen(t *testing.T) {
i += size
}
}
*/
......@@ -24,7 +24,7 @@ type Service struct {
maxMedianPath *Path //最大中位响应时间path
maxAveragePath *Path //最大平均响应时间path
maxDurationTracePoint *TracePoint //最大响应时间的tracePoint
qps int
qps float64 //QPS
//node相关
nodeMap map[string]*Node //节点列表
}
......@@ -225,7 +225,7 @@ func (s *Service) GetAverageDurationPathList() []*Path {
}
//获取qps
func (s *Service) GetQps() int {
func (s *Service) GetQps() float64 {
return s.qps
}
......@@ -295,18 +295,20 @@ func (s *Service) GetMaxDurationTracePoint() (*TracePoint, bool) {
return s.maxDurationTracePoint, s.maxDurationTracePoint != nil
}
//求平均
//求最大
func (s *Service) getNodeMapValue(f func(node *Node) int) int {
if len(s.nodeMap) == 0 {
return 0
}
sum := 0
max := 0
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 {
......
......@@ -126,6 +126,23 @@ func (sm *ServiceMap) GetMaxMemServiceList() []*Service {
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 {
rtn := make([]*Service, 0)
......@@ -144,8 +161,8 @@ func (sm *ServiceMap) GetMaxDiskServiceList() []*Service {
}
//获取qps
func (sm *ServiceMap) GetQps() int {
rtn := 0
func (sm *ServiceMap) GetQps() float64 {
rtn := float64(0)
for _, s := range sm.serviceMap {
rtn += s.GetQps()
}
......@@ -245,6 +262,11 @@ func (sm *ServiceMap) GetCount() int {
return sum
}
//获取service map
func (sm *ServiceMap) GetServiceMap() map[string]*Service {
return sm.serviceMap
}
//获取总响应时间
func (sm *ServiceMap) GetSumDuration() time.Duration {
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