dashboard: 服务监控请求时间间隔

This commit is contained in:
naiba
2021-09-02 23:45:21 +08:00
parent 0ea21598e8
commit 446ab3b1b8
12 changed files with 119 additions and 50 deletions

View File

@@ -1,7 +1,7 @@
package model
type ServiceItemResponse struct {
Monitor Monitor
Monitor *Monitor
TotalUp uint64
TotalDown uint64
CurrentUp uint64

View File

@@ -2,8 +2,10 @@ package model
import (
"encoding/json"
"fmt"
pb "github.com/naiba/nezha/proto"
"github.com/robfig/cron/v3"
"gorm.io/gorm"
)
@@ -36,9 +38,12 @@ type Monitor struct {
Type uint8
Target string
SkipServersRaw string
Duration uint64
Notify bool
Cover uint8
SkipServers map[uint64]bool `gorm:"-" json:"-"`
SkipServers map[uint64]bool `gorm:"-" json:"-"`
CronJobID cron.EntryID `gorm:"-" json:"-"`
}
func (m *Monitor) PB() *pb.Task {
@@ -49,6 +54,14 @@ func (m *Monitor) PB() *pb.Task {
}
}
func (m *Monitor) CronSpec() string {
if m.Duration == 0 {
// 默认间隔 30 秒
m.Duration = 30
}
return fmt.Sprintf("@every %ds", m.Duration)
}
func (m *Monitor) AfterFind(tx *gorm.DB) error {
var skipServers []uint64
if err := json.Unmarshal([]byte(m.SkipServersRaw), &skipServers); err != nil {