mirror of
https://github.com/TeaOSLab/EdgeAPI.git
synced 2025-12-29 17:26:35 +08:00
数据看板增加独立IP数量
This commit is contained in:
@@ -85,6 +85,22 @@ func (this *TrafficDailyStatDAO) IncreaseDailyStat(tx *dbs.Tx, day string, bytes
|
||||
return nil
|
||||
}
|
||||
|
||||
// IncreaseIPs 增加独立IP统计数据
|
||||
func (this *TrafficDailyStatDAO) IncreaseIPs(tx *dbs.Tx, day string, countIPs int64) error {
|
||||
if len(day) != 8 {
|
||||
return errors.New("invalid day '" + day + "'")
|
||||
}
|
||||
|
||||
return this.Query(tx).
|
||||
Param("countIPs", countIPs).
|
||||
InsertOrUpdateQuickly(maps.Map{
|
||||
"day": day,
|
||||
"countIPs": countIPs,
|
||||
}, maps.Map{
|
||||
"countIPs": dbs.SQL("countIPs+:countIPs"),
|
||||
})
|
||||
}
|
||||
|
||||
// FindDailyStats 获取日期之间统计
|
||||
func (this *TrafficDailyStatDAO) FindDailyStats(tx *dbs.Tx, dayFrom string, dayTo string) (result []*TrafficDailyStat, err error) {
|
||||
ones, err := this.Query(tx).
|
||||
|
||||
@@ -11,10 +11,20 @@ import (
|
||||
func TestTrafficDailyStatDAO_IncreaseDayBytes(t *testing.T) {
|
||||
dbs.NotifyReady()
|
||||
|
||||
now := time.Now()
|
||||
var now = time.Now()
|
||||
err := SharedTrafficDailyStatDAO.IncreaseDailyStat(nil, timeutil.Format("Ymd"), 1, 1, 1, 1, 1, 1)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
t.Log("ok", time.Since(now).Seconds()*1000, "ms")
|
||||
}
|
||||
|
||||
func TestTrafficDailyStatDAO_IncreaseIPs(t *testing.T) {
|
||||
dbs.NotifyReady()
|
||||
|
||||
var tx *dbs.Tx
|
||||
err := SharedTrafficDailyStatDAO.IncreaseIPs(tx, timeutil.Format("Ymd"), 123)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,19 @@
|
||||
package stats
|
||||
|
||||
import "github.com/iwind/TeaGo/dbs"
|
||||
|
||||
const (
|
||||
TrafficDailyStatField_Id dbs.FieldName = "id" // ID
|
||||
TrafficDailyStatField_Day dbs.FieldName = "day" // YYYYMMDD
|
||||
TrafficDailyStatField_CachedBytes dbs.FieldName = "cachedBytes" // 缓存流量
|
||||
TrafficDailyStatField_Bytes dbs.FieldName = "bytes" // 流量字节
|
||||
TrafficDailyStatField_CountRequests dbs.FieldName = "countRequests" // 请求数
|
||||
TrafficDailyStatField_CountCachedRequests dbs.FieldName = "countCachedRequests" // 缓存请求数
|
||||
TrafficDailyStatField_CountAttackRequests dbs.FieldName = "countAttackRequests" // 攻击量
|
||||
TrafficDailyStatField_AttackBytes dbs.FieldName = "attackBytes" // 攻击流量
|
||||
TrafficDailyStatField_CountIPs dbs.FieldName = "countIPs" // 独立IP数
|
||||
)
|
||||
|
||||
// TrafficDailyStat 总的流量统计(按天)
|
||||
type TrafficDailyStat struct {
|
||||
Id uint64 `field:"id"` // ID
|
||||
@@ -10,17 +24,19 @@ type TrafficDailyStat struct {
|
||||
CountCachedRequests uint64 `field:"countCachedRequests"` // 缓存请求数
|
||||
CountAttackRequests uint64 `field:"countAttackRequests"` // 攻击量
|
||||
AttackBytes uint64 `field:"attackBytes"` // 攻击流量
|
||||
CountIPs uint64 `field:"countIPs"` // 独立IP数
|
||||
}
|
||||
|
||||
type TrafficDailyStatOperator struct {
|
||||
Id interface{} // ID
|
||||
Day interface{} // YYYYMMDD
|
||||
CachedBytes interface{} // 缓存流量
|
||||
Bytes interface{} // 流量字节
|
||||
CountRequests interface{} // 请求数
|
||||
CountCachedRequests interface{} // 缓存请求数
|
||||
CountAttackRequests interface{} // 攻击量
|
||||
AttackBytes interface{} // 攻击流量
|
||||
Id any // ID
|
||||
Day any // YYYYMMDD
|
||||
CachedBytes any // 缓存流量
|
||||
Bytes any // 流量字节
|
||||
CountRequests any // 请求数
|
||||
CountCachedRequests any // 缓存请求数
|
||||
CountAttackRequests any // 攻击量
|
||||
AttackBytes any // 攻击流量
|
||||
CountIPs any // 独立IP数
|
||||
}
|
||||
|
||||
func NewTrafficDailyStatOperator() *TrafficDailyStatOperator {
|
||||
|
||||
Reference in New Issue
Block a user