mirror of
https://github.com/TeaOSLab/EdgeNode.git
synced 2025-11-09 03:50:27 +08:00
攻击流量统计使用上行流量
This commit is contained in:
@@ -312,17 +312,23 @@ func (this *HTTPRequest) doEnd() {
|
|||||||
|
|
||||||
// 流量统计
|
// 流量统计
|
||||||
// TODO 增加是否开启开关
|
// TODO 增加是否开启开关
|
||||||
// TODO 增加Header统计,考虑从Conn中读取
|
|
||||||
if this.ReqServer != nil {
|
if this.ReqServer != nil {
|
||||||
|
var countCached int64 = 0
|
||||||
|
var cachedBytes int64 = 0
|
||||||
|
|
||||||
|
var countAttacks int64 = 0
|
||||||
|
var attackBytes int64 = 0
|
||||||
|
|
||||||
if this.isCached {
|
if this.isCached {
|
||||||
stats.SharedTrafficStatManager.Add(this.ReqServer.Id, this.ReqHost, this.writer.SentBodyBytes(), this.writer.SentBodyBytes(), 1, 1, 0, 0, this.ReqServer.ShouldCheckTrafficLimit(), this.ReqServer.PlanId())
|
countCached = 1
|
||||||
} else {
|
cachedBytes = this.writer.SentBodyBytes()
|
||||||
|
}
|
||||||
if this.isAttack {
|
if this.isAttack {
|
||||||
stats.SharedTrafficStatManager.Add(this.ReqServer.Id, this.ReqHost, this.writer.SentBodyBytes(), 0, 1, 0, 1, this.writer.SentBodyBytes(), this.ReqServer.ShouldCheckTrafficLimit(), this.ReqServer.PlanId())
|
countAttacks = 1
|
||||||
} else {
|
attackBytes = this.CalculateSize()
|
||||||
stats.SharedTrafficStatManager.Add(this.ReqServer.Id, this.ReqHost, this.writer.SentBodyBytes(), 0, 1, 0, 0, 0, this.ReqServer.ShouldCheckTrafficLimit(), this.ReqServer.PlanId())
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
stats.SharedTrafficStatManager.Add(this.ReqServer.Id, this.ReqHost, this.writer.SentBodyBytes(), cachedBytes, 1, countCached, countAttacks, attackBytes, this.ReqServer.ShouldCheckTrafficLimit(), this.ReqServer.PlanId())
|
||||||
}
|
}
|
||||||
|
|
||||||
// 指标
|
// 指标
|
||||||
@@ -1278,6 +1284,28 @@ func (this *HTTPRequest) ContentLength() int64 {
|
|||||||
return this.RawReq.ContentLength
|
return this.RawReq.ContentLength
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CalculateSize 计算当前请求的尺寸(预估)
|
||||||
|
func (this *HTTPRequest) CalculateSize() (size int64) {
|
||||||
|
// Get /xxx HTTP/1.1
|
||||||
|
size += int64(len(this.RawReq.Method)) + 1
|
||||||
|
size += int64(len(this.RawReq.URL.String())) + 1
|
||||||
|
size += int64(len(this.RawReq.Proto)) + 1
|
||||||
|
for k, v := range this.RawReq.Header {
|
||||||
|
for _, v1 := range v {
|
||||||
|
size += int64(len(k) + 2 /** : **/ + len(v1))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
size += 1 /** \r\n **/
|
||||||
|
|
||||||
|
if this.RawReq.ContentLength > 0 {
|
||||||
|
size += this.RawReq.ContentLength
|
||||||
|
} else if len(this.requestBodyData) > 0 {
|
||||||
|
size += int64(len(this.requestBodyData))
|
||||||
|
}
|
||||||
|
return size
|
||||||
|
}
|
||||||
|
|
||||||
// Method 请求方法
|
// Method 请求方法
|
||||||
func (this *HTTPRequest) Method() string {
|
func (this *HTTPRequest) Method() string {
|
||||||
return this.RawReq.Method
|
return this.RawReq.Method
|
||||||
|
|||||||
Reference in New Issue
Block a user