访问日志可以使用分表查询

This commit is contained in:
GoEdgeLab
2022-04-17 16:18:43 +08:00
parent 53b1b2c572
commit 9d2eb11e1f
12 changed files with 212 additions and 17 deletions

View File

@@ -25,6 +25,7 @@ func (this *LogAction) RunGet(params struct {
RequestId string
FirewallPolicyId int64
GroupId int64
Partition int32 `default:"-1"`
}) {
if len(params.Day) == 0 {
params.Day = timeutil.Format("Y-m-d")
@@ -42,6 +43,7 @@ func (this *LogAction) RunGet(params struct {
size := int64(10)
resp, err := this.RPC().HTTPAccessLogRPC().ListHTTPAccessLogs(this.AdminContext(), &pb.ListHTTPAccessLogsRequest{
Partition: params.Partition,
RequestId: params.RequestId,
FirewallPolicyId: params.FirewallPolicyId,
FirewallRuleGroupId: params.GroupId,
@@ -74,6 +76,7 @@ func (this *LogAction) RunGet(params struct {
if len(params.RequestId) > 0 {
this.Data["hasPrev"] = true
prevResp, err := this.RPC().HTTPAccessLogRPC().ListHTTPAccessLogs(this.AdminContext(), &pb.ListHTTPAccessLogsRequest{
Partition: params.Partition,
RequestId: params.RequestId,
FirewallPolicyId: params.FirewallPolicyId,
FirewallRuleGroupId: params.GroupId,

View File

@@ -20,6 +20,8 @@ func (this *IndexAction) Init() {
func (this *IndexAction) RunGet(params struct {
Ip string
Partition int32 `default:"-1"`
}) {
this.Data["ip"] = params.Ip
@@ -103,9 +105,10 @@ func (this *IndexAction) RunGet(params struct {
// 访问日志
accessLogsResp, err := this.RPC().HTTPAccessLogRPC().ListHTTPAccessLogs(this.AdminContext(), &pb.ListHTTPAccessLogsRequest{
Day: timeutil.Format("Ymd"),
Ip: params.Ip,
Size: 20,
Partition: params.Partition,
Day: timeutil.Format("Ymd"),
Ip: params.Ip,
Size: 20,
})
if err != nil {
this.ErrorPage(err)
@@ -115,9 +118,10 @@ func (this *IndexAction) RunGet(params struct {
if len(accessLogs) == 0 {
// 查询昨天
accessLogsResp, err = this.RPC().HTTPAccessLogRPC().ListHTTPAccessLogs(this.AdminContext(), &pb.ListHTTPAccessLogsRequest{
Day: timeutil.Format("Ymd", time.Now().AddDate(0, 0, -1)),
Ip: params.Ip,
Size: 20,
Partition: params.Partition,
Day: timeutil.Format("Ymd", time.Now().AddDate(0, 0, -1)),
Ip: params.Ip,
Size: 20,
})
if err != nil {
this.ErrorPage(err)

View File

@@ -32,20 +32,38 @@ func (this *AccessLogsPopupAction) RunGet(params struct {
this.Data["ipFrom"] = item.IpFrom
this.Data["ipTo"] = item.IpTo
accessLogsResp, err := this.RPC().HTTPAccessLogRPC().ListHTTPAccessLogs(this.AdminContext(), &pb.ListHTTPAccessLogsRequest{
Day: timeutil.Format("Ymd"),
Keyword: "ip:" + item.IpFrom + "," + item.IpTo,
Size: 10,
})
// 多找几个Partition
var day = timeutil.Format("Ymd")
partitionsResp, err := this.RPC().HTTPAccessLogRPC().FindHTTPAccessLogPartitions(this.AdminContext(), &pb.FindHTTPAccessLogPartitionsRequest{Day: day})
if err != nil {
this.ErrorPage(err)
return
}
var accessLogs = accessLogsResp.HttpAccessLogs
if len(accessLogs) == 0 {
accessLogs = []*pb.HTTPAccessLog{}
var hasAccessLogs = false
for _, partition := range partitionsResp.ReversePartitions {
accessLogsResp, err := this.RPC().HTTPAccessLogRPC().ListHTTPAccessLogs(this.AdminContext(), &pb.ListHTTPAccessLogsRequest{
Partition: partition,
Day: day,
Keyword: "ip:" + item.IpFrom + "," + item.IpTo,
Size: 10,
})
if err != nil {
this.ErrorPage(err)
return
}
var accessLogs = accessLogsResp.HttpAccessLogs
if len(accessLogs) > 0 {
this.Data["accessLogs"] = accessLogs
hasAccessLogs = true
break
}
}
if !hasAccessLogs {
this.Data["accessLogs"] = []interface{}{}
}
this.Data["accessLogs"] = accessLogs
this.Show()
}

View File

@@ -0,0 +1,55 @@
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
package logs
import (
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
)
// CheckLogAction 检查是否有日志
type CheckLogAction struct {
actionutils.ParentAction
}
func (this *CheckLogAction) RunPost(params struct {
Day string
Partition int32
ServerId int64
RequestId string
ClusterId int64
NodeId int64
HasError bool
HasFirewallPolicy bool
Keyword string
Ip string
Domain string
Hour string
}) {
resp, err := this.RPC().HTTPAccessLogRPC().ListHTTPAccessLogs(this.AdminContext(), &pb.ListHTTPAccessLogsRequest{
Partition: params.Partition,
RequestId: params.RequestId,
NodeClusterId: params.ClusterId,
NodeId: params.NodeId,
ServerId: params.ServerId,
HasError: params.HasError,
HasFirewallPolicy: params.HasFirewallPolicy,
Day: params.Day,
HourFrom: params.Hour,
HourTo: params.Hour,
Keyword: params.Keyword,
Ip: params.Ip,
Domain: params.Domain,
Size: 1,
})
if err != nil {
this.ErrorPage(err)
return
}
this.Data["hasLogs"] = len(resp.HttpAccessLogs) > 0
this.Success()
}

View File

@@ -31,6 +31,7 @@ func (this *IndexAction) RunGet(params struct {
Domain string
HasError int
HasWAF int
Partition int32 `default:"-1"`
RequestId string
ServerId int64
@@ -56,6 +57,7 @@ func (this *IndexAction) RunGet(params struct {
this.Data["pageSize"] = params.PageSize
this.Data["isSlowQuery"] = false
this.Data["slowQueryCost"] = ""
this.Data["partition"] = params.Partition
day := params.Day
ipList := []string{}
@@ -71,6 +73,7 @@ func (this *IndexAction) RunGet(params struct {
var before = time.Now()
resp, err := this.RPC().HTTPAccessLogRPC().ListHTTPAccessLogs(this.AdminContext(), &pb.ListHTTPAccessLogsRequest{
Partition: params.Partition,
RequestId: params.RequestId,
NodeClusterId: params.ClusterId,
NodeId: params.NodeId,
@@ -117,6 +120,7 @@ func (this *IndexAction) RunGet(params struct {
if len(params.RequestId) > 0 {
this.Data["hasPrev"] = true
prevResp, err := this.RPC().HTTPAccessLogRPC().ListHTTPAccessLogs(this.AdminContext(), &pb.ListHTTPAccessLogsRequest{
Partition: params.Partition,
RequestId: params.RequestId,
NodeClusterId: params.ClusterId,
NodeId: params.NodeId,

View File

@@ -17,6 +17,7 @@ func init() {
Prefix("/servers/logs").
Get("", new(IndexAction)).
GetPost("/settings", new(SettingsAction)).
Post("/partitionData", new(PartitionDataAction)).
EndAll()
})
}

View File

@@ -0,0 +1,37 @@
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
package logs
import (
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"strings"
)
// PartitionDataAction 读取分区表
type PartitionDataAction struct {
actionutils.ParentAction
}
func (this *PartitionDataAction) RunPost(params struct {
Day string
}) {
var day = params.Day
day = strings.ReplaceAll(day, "-", "")
resp, err := this.RPC().HTTPAccessLogRPC().FindHTTPAccessLogPartitions(this.AdminContext(), &pb.FindHTTPAccessLogPartitionsRequest{
Day: day,
})
if err != nil {
this.ErrorPage(err)
return
}
if len(resp.Partitions) > 0 {
this.Data["partitions"] = resp.Partitions
} else {
this.Data["partitions"] = []int32{}
}
this.Success()
}

View File

@@ -33,6 +33,8 @@ func (this *HistoryAction) RunGet(params struct {
ClusterId int64
NodeId int64
Partition int32 `default:"-1"`
PageSize int
}) {
if len(params.Day) == 0 {
@@ -65,6 +67,7 @@ func (this *HistoryAction) RunGet(params struct {
this.Data["hasError"] = params.HasError
resp, err := this.RPC().HTTPAccessLogRPC().ListHTTPAccessLogs(this.AdminContext(), &pb.ListHTTPAccessLogsRequest{
Partition: params.Partition,
RequestId: params.RequestId,
ServerId: params.ServerId,
HasError: params.HasError > 0,
@@ -105,6 +108,7 @@ func (this *HistoryAction) RunGet(params struct {
if len(params.RequestId) > 0 {
this.Data["hasPrev"] = true
prevResp, err := this.RPC().HTTPAccessLogRPC().ListHTTPAccessLogs(this.AdminContext(), &pb.ListHTTPAccessLogsRequest{
Partition: params.Partition,
RequestId: params.RequestId,
ServerId: params.ServerId,
HasError: params.HasError > 0,

View File

@@ -57,10 +57,13 @@ func (this *IndexAction) RunPost(params struct {
ClusterId int64
NodeId int64
Partition int32 `default:"-1"`
Must *actions.Must
}) {
isReverse := len(params.RequestId) > 0
accessLogsResp, err := this.RPC().HTTPAccessLogRPC().ListHTTPAccessLogs(this.AdminContext(), &pb.ListHTTPAccessLogsRequest{
Partition: params.Partition,
ServerId: params.ServerId,
RequestId: params.RequestId,
Size: 20,

View File

@@ -27,6 +27,8 @@ func (this *TodayAction) RunGet(params struct {
ClusterId int64
NodeId int64
Partition int32 `default:"-1"`
PageSize int
}) {
this.Data["pageSize"] = params.PageSize
@@ -46,6 +48,7 @@ func (this *TodayAction) RunGet(params struct {
this.Data["nodeId"] = params.NodeId
resp, err := this.RPC().HTTPAccessLogRPC().ListHTTPAccessLogs(this.AdminContext(), &pb.ListHTTPAccessLogsRequest{
Partition: params.Partition,
RequestId: params.RequestId,
ServerId: params.ServerId,
HasError: params.HasError > 0,
@@ -85,6 +88,7 @@ func (this *TodayAction) RunGet(params struct {
if len(params.RequestId) > 0 {
this.Data["hasPrev"] = true
prevResp, err := this.RPC().HTTPAccessLogRPC().ListHTTPAccessLogs(this.AdminContext(), &pb.ListHTTPAccessLogsRequest{
Partition: params.Partition,
RequestId: params.RequestId,
ServerId: params.ServerId,
HasError: params.HasError > 0,