展示月流量使用情况

This commit is contained in:
naiba
2021-11-06 16:00:08 +08:00
parent 611cabf369
commit 561a3c85fb
8 changed files with 136 additions and 39 deletions

View File

@@ -2,10 +2,20 @@ package model
import (
"encoding/json"
"time"
"gorm.io/gorm"
)
type CycleTransferStats struct {
Name string
From time.Time
To time.Time
ServerName map[uint64]string
Transfer map[uint64]uint64
NextUpdate map[uint64]time.Time
}
type AlertRule struct {
Common
Name string
@@ -27,10 +37,14 @@ func (r *AlertRule) AfterFind(tx *gorm.DB) error {
return json.Unmarshal([]byte(r.RulesRaw), &r.Rules)
}
func (r *AlertRule) Snapshot(server *Server, db *gorm.DB) []interface{} {
func (r *AlertRule) Enabled() bool {
return r.Enable != nil && *r.Enable
}
func (r *AlertRule) Snapshot(cycleTransferStats *CycleTransferStats, server *Server, db *gorm.DB) []interface{} {
var point []interface{}
for i := 0; i < len(r.Rules); i++ {
point = append(point, r.Rules[i].Snapshot(server, db))
point = append(point, r.Rules[i].Snapshot(cycleTransferStats, server, db))
}
return point
}