Skip to content

Commit

Permalink
🚀 Add mute count for dashboard
Browse files Browse the repository at this point in the history
  • Loading branch information
Cairry committed Dec 28, 2024
1 parent db8693f commit 9ac8c2a
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions api/dashboardInfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"`
Expand All @@ -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)
// 告警分布
Expand Down Expand Up @@ -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{
Expand Down

0 comments on commit 9ac8c2a

Please sign in to comment.