对服务增加基础的数据统计

This commit is contained in:
GoEdgeLab
2021-01-25 16:40:31 +08:00
parent 5eef6ac267
commit f16d07c43f
11 changed files with 354 additions and 28 deletions

View File

@@ -6,6 +6,7 @@ import (
"github.com/TeaOSLab/EdgeCommon/pkg/configutils"
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
teaconst "github.com/TeaOSLab/EdgeNode/internal/const"
"github.com/TeaOSLab/EdgeNode/internal/stats"
"github.com/TeaOSLab/EdgeNode/internal/utils"
"github.com/iwind/TeaGo/types"
"net"
@@ -148,6 +149,11 @@ func (this *HTTPRequest) Do() {
// 开始调用
func (this *HTTPRequest) doBegin() {
// 统计
if this.web.StatRef != nil && this.web.StatRef.IsOn {
this.doStat()
}
// 跳转
if len(this.web.HostRedirects) > 0 {
if this.doHostRedirect() {
@@ -219,7 +225,7 @@ func (this *HTTPRequest) doEnd() {
// 流量统计
// TODO 增加是否开启开关
if this.Server != nil {
SharedTrafficStatManager.Add(this.Server.Id, this.writer.sentBodyBytes)
stats.SharedTrafficStatManager.Add(this.Server.Id, this.writer.sentBodyBytes)
}
}
@@ -321,6 +327,11 @@ func (this *HTTPRequest) configureWeb(web *serverconfigs.HTTPWebConfig, isTop bo
this.web.HostRedirects = web.HostRedirects
}
// stat
if web.StatRef != nil && (web.StatRef.IsPrior || isTop) {
this.web.StatRef = web.StatRef
}
// 重写规则
if len(web.RewriteRefs) > 0 {
for index, ref := range web.RewriteRefs {