From 9ac8c2ac9ce5ae20f0e6b88d8d4533fc0baeb0ee Mon Sep 17 00:00:00 2001 From: Cairry <115769353+Cairry@users.noreply.github.com> Date: Sat, 28 Dec 2024 23:10:52 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=9A=80=20Add=20mute=20count=20for=20dashb?= =?UTF-8?q?oard?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/dashboardInfo.go | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/api/dashboardInfo.go b/api/dashboardInfo.go index 26a7e38..f3bbb9b 100644 --- a/api/dashboardInfo.go +++ b/api/dashboardInfo.go @@ -2,6 +2,7 @@ package api import ( "github.com/gin-gonic/gin" + "github.com/zeromicro/go-zero/core/logc" "watchAlert/internal/middleware" "watchAlert/internal/models" "watchAlert/pkg/ctx" @@ -26,6 +27,7 @@ func (di DashboardInfoController) API(gin *gin.RouterGroup) { type ResponseDashboardInfo struct { CountAlertRules int64 `json:"countAlertRules"` + CurMutes int64 `json:"curMutes"` CurAlerts int `json:"curAlerts"` CurAlertList []string `json:"curAlertList"` AlarmDistribution AlarmDistribution `json:"alarmDistribution"` @@ -39,16 +41,14 @@ type AlarmDistribution struct { } func (di DashboardInfoController) GetDashboardInfo(context *gin.Context) { - var ( // 规则总数 countAlertRules int64 // 当前告警 keys []string + c = ctx.DO() ) - c := ctx.DO() - tid, _ := context.Get("TenantID") tidString := tid.(string) // 告警分布 @@ -85,11 +85,18 @@ func (di DashboardInfoController) GetDashboardInfo(context *gin.Context) { curAlertList = append(curAlertList, c.Redis.Event().GetCache(v).Annotations) } + res, err := c.DB.Silence().List(models.AlertSilenceQuery{TenantId: tidString, Status: 0}) + if err != nil { + logc.Errorf(c.Ctx, "List silence failed, err: %s", err.Error()) + return + } + var resource []models.ServiceResource c.DB.DB().Model(&models.ServiceResource{}).Find(&resource) response.Success(context, ResponseDashboardInfo{ CountAlertRules: countAlertRules, + CurMutes: res.Total, CurAlerts: len(keys), CurAlertList: curAlertList, AlarmDistribution: AlarmDistribution{