mirror of
https://github.com/TeaOSLab/EdgeCommon.git
synced 2025-11-05 14:20:24 +08:00
优化指标统计数据清理
This commit is contained in:
@@ -136,6 +136,24 @@ func (this *MetricItemConfig) ServerExpiresTime() string {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ServerExpiresDay 根据周期计算服务器端数据过期日期
|
||||||
|
func (this *MetricItemConfig) ServerExpiresDay() string {
|
||||||
|
switch this.PeriodUnit {
|
||||||
|
case MetricItemPeriodUnitMonth:
|
||||||
|
return timeutil.Format("Ymd", time.Now().AddDate(0, -(this.Period*4), 0))
|
||||||
|
case MetricItemPeriodUnitWeek:
|
||||||
|
return timeutil.FormatTime("Ymd", time.Now().Unix()-86400*7*int64(this.Period*5))
|
||||||
|
case MetricItemPeriodUnitDay:
|
||||||
|
return timeutil.FormatTime("Ymd", time.Now().Unix()-86400*int64(this.Period*32))
|
||||||
|
case MetricItemPeriodUnitHour:
|
||||||
|
return timeutil.FormatTime("Ymd", time.Now().Unix()-3600*int64(this.Period*25)-86400)
|
||||||
|
case MetricItemPeriodUnitMinute:
|
||||||
|
return timeutil.FormatTime("Ymd", time.Now().Unix()-60*int64(this.Period*60)-86400)
|
||||||
|
default:
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// LocalExpiresTime 根据周期计算本地端过期时间
|
// LocalExpiresTime 根据周期计算本地端过期时间
|
||||||
func (this *MetricItemConfig) LocalExpiresTime() string {
|
func (this *MetricItemConfig) LocalExpiresTime() string {
|
||||||
switch this.PeriodUnit {
|
switch this.PeriodUnit {
|
||||||
|
|||||||
@@ -58,3 +58,26 @@ func TestMetricItemConfig_CurrentTime_Minute(t *testing.T) {
|
|||||||
t.Log(period, ":", item.CurrentTime())
|
t.Log(period, ":", item.CurrentTime())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestMetricItemConfig_ServerExpiresDay(t *testing.T) {
|
||||||
|
{
|
||||||
|
var config = &MetricItemConfig{Period: 3, PeriodUnit: MetricItemPeriodUnitMonth}
|
||||||
|
t.Log(config.ServerExpiresDay())
|
||||||
|
}
|
||||||
|
{
|
||||||
|
var config = &MetricItemConfig{Period: 3, PeriodUnit: MetricItemPeriodUnitWeek}
|
||||||
|
t.Log(config.ServerExpiresDay())
|
||||||
|
}
|
||||||
|
{
|
||||||
|
var config = &MetricItemConfig{Period: 3, PeriodUnit: MetricItemPeriodUnitDay}
|
||||||
|
t.Log(config.ServerExpiresDay())
|
||||||
|
}
|
||||||
|
{
|
||||||
|
var config = &MetricItemConfig{Period: 3, PeriodUnit: MetricItemPeriodUnitHour}
|
||||||
|
t.Log(config.ServerExpiresDay())
|
||||||
|
}
|
||||||
|
{
|
||||||
|
var config = &MetricItemConfig{Period: 3, PeriodUnit: MetricItemPeriodUnitMinute}
|
||||||
|
t.Log(config.ServerExpiresDay())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -13,6 +13,10 @@ const (
|
|||||||
MetricItemCategoryUDP MetricItemCategory = "udp"
|
MetricItemCategoryUDP MetricItemCategory = "udp"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func FindAllMetricItemCategoryCodes() []MetricItemCategory {
|
||||||
|
return []MetricItemCategory{MetricItemCategoryHTTP, MetricItemCategoryTCP, MetricItemCategoryUDP}
|
||||||
|
}
|
||||||
|
|
||||||
// MetricItemPeriodUnit 指标周期单位
|
// MetricItemPeriodUnit 指标周期单位
|
||||||
type MetricItemPeriodUnit = string
|
type MetricItemPeriodUnit = string
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user