实现实时展示访问日志

This commit is contained in:
GoEdgeLab
2020-10-10 19:22:17 +08:00
parent a507d53b03
commit 8d24063e80
7 changed files with 122 additions and 5 deletions

View File

@@ -1,6 +1,11 @@
package log
import "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
import (
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/iwind/TeaGo/actions"
timeutil "github.com/iwind/TeaGo/utils/time"
)
type IndexAction struct {
actionutils.ParentAction
@@ -11,6 +16,46 @@ func (this *IndexAction) Init() {
this.SecondMenu("index")
}
func (this *IndexAction) RunGet(params struct{}) {
func (this *IndexAction) RunGet(params struct {
ServerId int64
RequestId string
}) {
this.Data["serverId"] = params.ServerId
this.Data["requestId"] = params.RequestId
this.Show()
}
func (this *IndexAction) RunPost(params struct {
ServerId int64
RequestId string
Must *actions.Must
}) {
isReverse := len(params.RequestId) > 0
accessLogsResp, err := this.RPC().HTTPAccessLogRPC().ListHTTPAccessLogs(this.AdminContext(), &pb.ListHTTPAccessLogsRequest{
ServerId: params.ServerId,
RequestId: params.RequestId,
Size: 20,
Day: timeutil.Format("Ymd"),
Reverse: isReverse,
})
if err != nil {
this.ErrorPage(err)
return
}
accessLogs := accessLogsResp.AccessLogs
if len(accessLogs) == 0 {
accessLogs = []*pb.HTTPAccessLog{}
}
this.Data["accessLogs"] = accessLogs
if len(accessLogs) > 0 {
this.Data["requestId"] = accessLogs[0].RequestId
} else {
this.Data["requestId"] = params.RequestId
}
this.Data["hasMore"] = accessLogsResp.HasMore
this.Success()
}

View File

@@ -12,7 +12,7 @@ func init() {
Helper(helpers.NewUserMustAuth()).
Helper(serverutils.NewServerHelper()).
Prefix("/servers/server/log").
Get("", new(IndexAction)).
GetPost("", new(IndexAction)).
EndAll()
})
}