package service import ( "context" "go-admin/app/observe/models" "go-admin/app/observe/service/dto" "go-admin/render" "go-admin/render/report" "github.com/go-admin-team/go-admin-core/logger" ) type ScopeGraphBasic struct { ADD []render.NodeSummary `json:"add"` Update []render.NodeSummary `json:"update"` Remove []render.NodeSummary `json:"remove"` Reset bool `json:"reset"` } func (sgb *ScopeGraphBasic) setShape(icon string) string { switch icon { case "cloud": return "cloud" case "mysql": return "cylinder" case "clickhouse": return "cylinder" case "mssql": return "cylinder" case "oracle": return "cylinder" case "db2": return "cylinder" case "postgresql": return "cylinder" case "hive": return "cylinder" case "mariadb": return "cylinder" case "sqlite": return "cylinder" case "mongodb": return "cylinder" case "redis": return "cylinder" case "neo4j": return "cylinder" case "elasticsearch": return "cylinder" case "opensearch": return "cylinder" case "memcached": return "cylinder" case "other_sql": return "cylinder" case "kafka": return "dottedcylinder" case "activemq": return "dottedcylinder" case "jms": return "dottedcylinder" case "rabbitmq": return "dottedcylinder" case "rocketmq": return "dottedcylinder" default: return "circle" } } func (sgb *ScopeGraphBasic) AddNoSoulGraph( svc *Service, ctx context.Context, req *dto.ServiceGetEdgesReq, resp *models.Graph) { if err := svc.GetNoSoulGraph(ctx, req, resp); err != nil { logger.Error("get no-soul graph err: ", err.Error()) // api.Error(http.StatusInternalServerError, err, err.Error()) return } for _, node := range resp.Nodes { ns := render.NodeSummary{ BasicNodeSummary: render.BasicNodeSummary{ ID: node.ID, Label: node.Title, //钻取下级 从属依赖下级 LabelMinor: node.SubTitle, //钻取下下级 从属依赖下下级 Shape: sgb.setShape(node.Icon), Color: "DI", }, } //TODO: for _, es := range resp.Edges { if es.Source == node.ID { ns.Adjacency = append(ns.Adjacency, es.Target) } } sgb.ADD = append(sgb.ADD, ns) } sgb.Reset = true } func (sgb *ScopeGraphBasic) UpdateGraph( svc *Service, ctx context.Context, req *dto.ServiceGetEdgesReq, resp *models.Graph) { if err := svc.GetGraph(ctx, req, resp); err != nil { logger.Error("get graph err: ", err.Error()) // api.Error(http.StatusInternalServerError, err, err.Error()) return } for _, node := range resp.Nodes { ns := render.NodeSummary{ BasicNodeSummary: render.BasicNodeSummary{ ID: node.ID, Label: node.Title, //钻取下级 从属依赖下级 LabelMinor: node.SubTitle, //钻取下下级 从属依赖下下级 Shape: sgb.setShape(node.Icon), Color: "G", // Tag: "camera", }, } if node.Apdex == 0 { node.Apdex = 1 } // 当成功和失败都为0时,为系统组件,系统组件标记为100%成功率(暂定) if node.ArcFaild == 0 && node.ArcSuccess == 0 { node.ArcSuccess = 1 } mrApdex := report.MetricRow{ ID: "apdex", Label: "可用性", Format: "percent", Value: node.Apdex * 100, Priority: 1, Metric: report.Metric{ Min: 0, Max: 100, }, } mrErr := report.MetricRow{ ID: "request failed", Label: "错误率", Format: "percent", Value: node.ArcFaild * 100, Priority: 1, Metric: report.Metric{ Min: 0, Max: 100, }, } mrSucc := report.MetricRow{ ID: "request success", Label: "成功率", Format: "percent", Value: node.ArcSuccess * 100, Priority: 2, Metric: report.Metric{ Min: 0, Max: 100, }, } // mrSend := report.MetricRow{ // ID: "Send Req", // Label: "发送量", // Format: "", // Value: float64(node.Send), // Priority: 3, // Metric: report.Metric{ // Min: 0, // Max: float64(node.Send) + float64(node.Receive), // }, // } // mrReceive := report.MetricRow{ // ID: "Receive Req", // Label: "接收量", // Format: "", // Value: float64(node.Receive), // Priority: 4, // Metric: report.Metric{ // Min: 0, // Max: float64(node.Send) + float64(node.Receive), // }, // } if node.ArcFaild+node.ArcSuccess == 0 { ns.Color = "DI" } else { if node.ArcSuccess < 0.6 || node.Apdex < 0.4 { ns.Color = "R" } else if (node.ArcSuccess >= 0.6 && node.ArcSuccess < 0.8) || (node.Apdex >= 0.4 && node.Apdex < 0.8) { ns.Color = "Y" } } ns.Metrics = append(ns.Metrics, mrApdex) ns.Metrics = append(ns.Metrics, mrErr) ns.Metrics = append(ns.Metrics, mrSucc) // ns.Metrics = append(ns.Metrics, mrSend) // ns.Metrics = append(ns.Metrics, mrReceive) for _, es := range resp.Edges { if es.Source == node.ID { ns.Adjacency = append(ns.Adjacency, es.Target) } } sgb.Update = append(sgb.Update, ns) } // sgb.Reset = true }