实现基础的统计指标

This commit is contained in:
刘祥超
2021-06-30 20:50:17 +08:00
parent e4b59c5e85
commit 32cb66db4c
14 changed files with 1481 additions and 110 deletions

View File

@@ -2,38 +2,59 @@
package serverconfigs
import (
"github.com/TeaOSLab/EdgeCommon/pkg/configutils"
"testing"
)
import "testing"
func TestMetricItemConfig_ProcessRequest(t *testing.T) {
var metric = &MetricItemConfig{
Keys: []string{"${remoteAddr}", "${status}", "${requestPath}"},
Value: "${trafficIn}",
func TestMetricItemConfig_CurrentTime_Month(t *testing.T) {
for _, period := range []int{1, 2, 3, 4, 5, 100} {
var item = &MetricItemConfig{
Period: period,
PeriodUnit: MetricItemPeriodUnitMonth,
}
_ = item.Init()
t.Logf(item.CurrentTime())
}
key, hash, value := metric.ParseRequest(func(s string) string {
return configutils.ParseVariables(s, func(varName string) (value string) {
switch varName {
case "trafficIn":
return "1000"
}
return "[" + varName + "]"
})
})
t.Log("key:", key, "hash:", hash)
t.Logf("value: %f", value)
}
func BenchmarkMetricItemConfig_ProcessRequest(b *testing.B) {
var metric = &MetricItemConfig{
Keys: []string{"${remoteAddr}", "${status}"},
}
for i := 0; i < b.N; i++ {
metric.ParseRequest(func(s string) string {
return configutils.ParseVariables(s, func(varName string) (value string) {
return "[" + varName + "]"
})
})
func TestMetricItemConfig_CurrentTime_Week(t *testing.T) {
for _, period := range []int{1, 2, 3, 4, 5} {
var item = &MetricItemConfig{
Period: period,
PeriodUnit: MetricItemPeriodUnitWeek,
}
_ = item.Init()
t.Log(period, ":", item.CurrentTime())
}
}
func TestMetricItemConfig_CurrentTime_Day(t *testing.T) {
for _, period := range []int{1, 2, 3, 4, 5, 13} {
var item = &MetricItemConfig{
Period: period,
PeriodUnit: MetricItemPeriodUnitDay,
}
_ = item.Init()
t.Log(period, ":", item.CurrentTime())
}
}
func TestMetricItemConfig_CurrentTime_Hour(t *testing.T) {
for _, period := range []int{1, 2, 3, 4, 5, 13} {
var item = &MetricItemConfig{
Period: period,
PeriodUnit: MetricItemPeriodUnitHour,
}
_ = item.Init()
t.Log(period, ":", item.CurrentTime())
}
}
func TestMetricItemConfig_CurrentTime_Minute(t *testing.T) {
for _, period := range []int{1, 2, 3, 4, 5, 13} {
var item = &MetricItemConfig{
Period: period,
PeriodUnit: MetricItemPeriodUnitMinute,
}
_ = item.Init()
t.Log(period, ":", item.CurrentTime())
}
}