实现实时展示访问日志

This commit is contained in:
刘祥超
2020-10-10 19:22:12 +08:00
parent 11fb3ac668
commit b22ebe1ca6

View File

@@ -3,10 +3,14 @@ package nodes
import ( import (
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb" "github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs" "github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
"strconv"
"strings" "strings"
"sync/atomic"
"time" "time"
) )
var requestId int64 = 1_0000_0000_0000_0000
// 日志 // 日志
func (this *HTTPRequest) log() { func (this *HTTPRequest) log() {
// 计算请求时间 // 计算请求时间
@@ -73,6 +77,7 @@ func (this *HTTPRequest) log() {
} }
accessLog := &pb.HTTPAccessLog{ accessLog := &pb.HTTPAccessLog{
RequestId: strconv.FormatInt(this.requestFromTime.UnixNano(), 10) + strconv.FormatInt(atomic.AddInt64(&requestId, 1), 10) + sharedNodeConfig.PaddedId(),
NodeId: sharedNodeConfig.Id, NodeId: sharedNodeConfig.Id,
ServerId: this.Server.Id, ServerId: this.Server.Id,
RemoteAddr: this.requestRemoteAddr(), RemoteAddr: this.requestRemoteAddr(),