mirror of
https://github.com/TeaOSLab/EdgeAPI.git
synced 2025-11-08 03:00:26 +08:00
服务流量接口增加5分钟查询接口
This commit is contained in:
@@ -437,6 +437,22 @@ func (this *ServerDailyStatDAO) FindDailyStats(tx *dbs.Tx, serverId int64, dayFr
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FindStatsWithDay 按天查找5分钟级统计
|
||||||
|
// day YYYYMMDD
|
||||||
|
func (this *ServerDailyStatDAO) FindStatsWithDay(tx *dbs.Tx, serverId int64, day string) (result []*ServerDailyStat, err error) {
|
||||||
|
if !regexp.MustCompile(`^\d{8}$`).MatchString(day) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = this.Query(tx).
|
||||||
|
Attr("serverId", serverId).
|
||||||
|
Attr("day", day).
|
||||||
|
AscPk().
|
||||||
|
Slice(&result).
|
||||||
|
FindAll()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// FindMonthlyStatsWithPlan 查找某月有套餐的流量
|
// FindMonthlyStatsWithPlan 查找某月有套餐的流量
|
||||||
// month YYYYMM
|
// month YYYYMM
|
||||||
func (this *ServerDailyStatDAO) FindMonthlyStatsWithPlan(tx *dbs.Tx, month string) (result []*ServerDailyStat, err error) {
|
func (this *ServerDailyStatDAO) FindMonthlyStatsWithPlan(tx *dbs.Tx, month string) (result []*ServerDailyStat, err error) {
|
||||||
|
|||||||
@@ -192,6 +192,38 @@ func (this *ServerDailyStatService) FindLatestServerMinutelyStats(ctx context.Co
|
|||||||
return &pb.FindLatestServerMinutelyStatsResponse{Stats: result}, nil
|
return &pb.FindLatestServerMinutelyStatsResponse{Stats: result}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FindServer5MinutelyStatsWithDay 读取某天的5分钟间隔流量
|
||||||
|
func (this *ServerDailyStatService) FindServer5MinutelyStatsWithDay(ctx context.Context, req *pb.FindServer5MinutelyStatsWithDayRequest) (*pb.FindServer5MinutelyStatsWithDayResponse, error) {
|
||||||
|
_, err := this.ValidateAdmin(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
var tx = this.NullTx()
|
||||||
|
if len(req.Day) == 0 {
|
||||||
|
req.Day = timeutil.Format("Ymd")
|
||||||
|
}
|
||||||
|
|
||||||
|
dailyStats, err := models.SharedServerDailyStatDAO.FindStatsWithDay(tx, req.ServerId, req.Day)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
var pbStats = []*pb.FindServer5MinutelyStatsWithDayResponse_Stat{}
|
||||||
|
for _, stat := range dailyStats {
|
||||||
|
pbStats = append(pbStats, &pb.FindServer5MinutelyStatsWithDayResponse_Stat{
|
||||||
|
Day: stat.Day,
|
||||||
|
TimeFrom: stat.TimeFrom,
|
||||||
|
TimeTo: stat.TimeTo,
|
||||||
|
Bytes: int64(stat.Bytes),
|
||||||
|
CachedBytes: int64(stat.CachedBytes),
|
||||||
|
CountRequests: int64(stat.CountRequests),
|
||||||
|
CountCachedRequests: int64(stat.CountCachedRequests),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
return &pb.FindServer5MinutelyStatsWithDayResponse{Stats: pbStats}, nil
|
||||||
|
}
|
||||||
|
|
||||||
// FindLatestServerDailyStats 按天读取统计数据
|
// FindLatestServerDailyStats 按天读取统计数据
|
||||||
func (this *ServerDailyStatService) FindLatestServerDailyStats(ctx context.Context, req *pb.FindLatestServerDailyStatsRequest) (*pb.FindLatestServerDailyStatsResponse, error) {
|
func (this *ServerDailyStatService) FindLatestServerDailyStats(ctx context.Context, req *pb.FindLatestServerDailyStatsRequest) (*pb.FindLatestServerDailyStatsResponse, error) {
|
||||||
_, err := this.ValidateAdmin(ctx)
|
_, err := this.ValidateAdmin(ctx)
|
||||||
|
|||||||
Reference in New Issue
Block a user