mirror of
https://github.com/TeaOSLab/EdgeAPI.git
synced 2026-01-04 06:16:35 +08:00
可以自行设定指标数据保留时间
This commit is contained in:
@@ -108,10 +108,10 @@ func (this *MetricItemDAO) FindMetricItemName(tx *dbs.Tx, id int64) (string, err
|
||||
}
|
||||
|
||||
// CreateItem 创建指标
|
||||
func (this *MetricItemDAO) CreateItem(tx *dbs.Tx, code string, category string, name string, keys []string, period int32, periodUnit string, value string, isPublic bool) (int64, error) {
|
||||
func (this *MetricItemDAO) CreateItem(tx *dbs.Tx, code string, category string, name string, keys []string, period int32, periodUnit string, expiresPeriod int32, value string, isPublic bool) (int64, error) {
|
||||
sort.Strings(keys)
|
||||
|
||||
op := NewMetricItemOperator()
|
||||
var op = NewMetricItemOperator()
|
||||
op.Code = code
|
||||
op.Category = category
|
||||
op.Name = name
|
||||
@@ -126,6 +126,7 @@ func (this *MetricItemDAO) CreateItem(tx *dbs.Tx, code string, category string,
|
||||
}
|
||||
op.Period = period
|
||||
op.PeriodUnit = periodUnit
|
||||
op.ExpiresPeriod = expiresPeriod
|
||||
op.Value = value
|
||||
op.IsPublic = isPublic
|
||||
op.IsOn = true
|
||||
@@ -146,7 +147,7 @@ func (this *MetricItemDAO) CreateItem(tx *dbs.Tx, code string, category string,
|
||||
}
|
||||
|
||||
// UpdateItem 修改\指标
|
||||
func (this *MetricItemDAO) UpdateItem(tx *dbs.Tx, itemId int64, name string, keys []string, period int32, periodUnit string, value string, isOn bool, isPublic bool) error {
|
||||
func (this *MetricItemDAO) UpdateItem(tx *dbs.Tx, itemId int64, name string, keys []string, period int32, periodUnit string, expiresPeriod int32, value string, isOn bool, isPublic bool) error {
|
||||
if itemId <= 0 {
|
||||
return errors.New("invalid itemId")
|
||||
}
|
||||
@@ -168,7 +169,7 @@ func (this *MetricItemDAO) UpdateItem(tx *dbs.Tx, itemId int64, name string, key
|
||||
}
|
||||
|
||||
// 保存
|
||||
op := NewMetricItemOperator()
|
||||
var op = NewMetricItemOperator()
|
||||
op.Id = itemId
|
||||
op.Name = name
|
||||
if len(keys) > 0 {
|
||||
@@ -182,6 +183,7 @@ func (this *MetricItemDAO) UpdateItem(tx *dbs.Tx, itemId int64, name string, key
|
||||
}
|
||||
op.Period = period
|
||||
op.PeriodUnit = periodUnit
|
||||
op.ExpiresPeriod = expiresPeriod
|
||||
op.Value = value
|
||||
op.IsOn = isOn
|
||||
if versionChanged {
|
||||
@@ -282,14 +284,15 @@ func (this *MetricItemDAO) ComposeItemConfig(tx *dbs.Tx, itemId int64) (*serverc
|
||||
}
|
||||
var item = one.(*MetricItem)
|
||||
var config = &serverconfigs.MetricItemConfig{
|
||||
Id: int64(item.Id),
|
||||
IsOn: item.IsOn,
|
||||
Period: types.Int(item.Period),
|
||||
PeriodUnit: item.PeriodUnit,
|
||||
Category: item.Category,
|
||||
Value: item.Value,
|
||||
Keys: item.DecodeKeys(),
|
||||
Version: types.Int32(item.Version),
|
||||
Id: int64(item.Id),
|
||||
IsOn: item.IsOn,
|
||||
Period: types.Int(item.Period),
|
||||
PeriodUnit: item.PeriodUnit,
|
||||
ExpiresPeriod: types.Int(item.ExpiresPeriod),
|
||||
Category: item.Category,
|
||||
Value: item.Value,
|
||||
Keys: item.DecodeKeys(),
|
||||
Version: types.Int32(item.Version),
|
||||
}
|
||||
|
||||
return config, nil
|
||||
@@ -301,14 +304,15 @@ func (this *MetricItemDAO) ComposeItemConfigWithItem(item *MetricItem) *serverco
|
||||
return nil
|
||||
}
|
||||
var config = &serverconfigs.MetricItemConfig{
|
||||
Id: int64(item.Id),
|
||||
IsOn: item.IsOn,
|
||||
Period: types.Int(item.Period),
|
||||
PeriodUnit: item.PeriodUnit,
|
||||
Category: item.Category,
|
||||
Value: item.Value,
|
||||
Keys: item.DecodeKeys(),
|
||||
Version: types.Int32(item.Version),
|
||||
Id: int64(item.Id),
|
||||
IsOn: item.IsOn,
|
||||
Period: types.Int(item.Period),
|
||||
PeriodUnit: item.PeriodUnit,
|
||||
ExpiresPeriod: types.Int(item.ExpiresPeriod),
|
||||
Category: item.Category,
|
||||
Value: item.Value,
|
||||
Keys: item.DecodeKeys(),
|
||||
Version: types.Int32(item.Version),
|
||||
}
|
||||
|
||||
return config
|
||||
|
||||
@@ -1,6 +1,13 @@
|
||||
package models
|
||||
package models_test
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/db/models"
|
||||
_ "github.com/go-sql-driver/mysql"
|
||||
_ "github.com/iwind/TeaGo/bootstrap"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestMetricStatDAO_Clean(t *testing.T) {
|
||||
var dao = models.NewMetricStatDAO()
|
||||
t.Log(dao.Clean(nil))
|
||||
}
|
||||
|
||||
@@ -3,12 +3,12 @@ package models
|
||||
import (
|
||||
"encoding/json"
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/goman"
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/remotelogs"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
|
||||
_ "github.com/go-sql-driver/mysql"
|
||||
"github.com/iwind/TeaGo/Tea"
|
||||
"github.com/iwind/TeaGo/dbs"
|
||||
"github.com/iwind/TeaGo/lists"
|
||||
"github.com/iwind/TeaGo/logs"
|
||||
"github.com/iwind/TeaGo/maps"
|
||||
"github.com/iwind/TeaGo/rands"
|
||||
timeutil "github.com/iwind/TeaGo/utils/time"
|
||||
@@ -26,7 +26,7 @@ func init() {
|
||||
for range ticker.C {
|
||||
err := SharedMetricStatDAO.Clean(nil)
|
||||
if err != nil {
|
||||
logs.Println("SharedMetricStatDAO: clean expired data failed: " + err.Error())
|
||||
remotelogs.Error("SharedMetricStatDAO", "clean expired data failed: "+err.Error())
|
||||
}
|
||||
}
|
||||
})
|
||||
@@ -474,9 +474,10 @@ func (this *MetricStatDAO) Clean(tx *dbs.Tx) error {
|
||||
}
|
||||
for _, item := range items {
|
||||
var config = &serverconfigs.MetricItemConfig{
|
||||
Id: int64(item.Id),
|
||||
Period: int(item.Period),
|
||||
PeriodUnit: item.PeriodUnit,
|
||||
Id: int64(item.Id),
|
||||
Period: int(item.Period),
|
||||
PeriodUnit: item.PeriodUnit,
|
||||
ExpiresPeriod: int(item.ExpiresPeriod),
|
||||
}
|
||||
var expiresDay = config.ServerExpiresDay()
|
||||
_, err := this.Query(tx).
|
||||
|
||||
@@ -2,11 +2,11 @@ package models
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/goman"
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/remotelogs"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
|
||||
_ "github.com/go-sql-driver/mysql"
|
||||
"github.com/iwind/TeaGo/Tea"
|
||||
"github.com/iwind/TeaGo/dbs"
|
||||
"github.com/iwind/TeaGo/logs"
|
||||
"github.com/iwind/TeaGo/maps"
|
||||
"github.com/iwind/TeaGo/rands"
|
||||
timeutil "github.com/iwind/TeaGo/utils/time"
|
||||
@@ -23,7 +23,7 @@ func init() {
|
||||
for range ticker.C {
|
||||
err := SharedMetricSumStatDAO.Clean(nil)
|
||||
if err != nil {
|
||||
logs.Println("SharedMetricSumStatDAO: clean expired data failed: " + err.Error())
|
||||
remotelogs.Error("SharedMetricSumStatDAO", "clean expired data failed: "+err.Error())
|
||||
}
|
||||
}
|
||||
})
|
||||
@@ -180,9 +180,10 @@ func (this *MetricSumStatDAO) Clean(tx *dbs.Tx) error {
|
||||
}
|
||||
for _, item := range items {
|
||||
var config = &serverconfigs.MetricItemConfig{
|
||||
Id: int64(item.Id),
|
||||
Period: int(item.Period),
|
||||
PeriodUnit: item.PeriodUnit,
|
||||
Id: int64(item.Id),
|
||||
Period: int(item.Period),
|
||||
PeriodUnit: item.PeriodUnit,
|
||||
ExpiresPeriod: int(item.ExpiresPeriod),
|
||||
}
|
||||
var expiresDay = config.ServerExpiresDay()
|
||||
_, err := this.Query(tx).
|
||||
|
||||
Reference in New Issue
Block a user