mirror of
https://github.com/TeaOSLab/EdgeNode.git
synced 2026-02-08 19:05:37 +08:00
实现节点运行日志上传
This commit is contained in:
@@ -2,7 +2,7 @@ package caches
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
|
||||
"github.com/iwind/TeaGo/logs"
|
||||
"github.com/TeaOSLab/EdgeNode/internal/logs"
|
||||
"strconv"
|
||||
"sync"
|
||||
)
|
||||
@@ -35,7 +35,7 @@ func (this *Manager) UpdatePolicies(newPolicies []*serverconfigs.HTTPCachePolicy
|
||||
// 停止旧有的
|
||||
for _, oldPolicy := range this.policyMap {
|
||||
if !this.containsInt64(newPolicyIds, oldPolicy.Id) {
|
||||
logs.Println("[CACHE]remove policy", strconv.FormatInt(oldPolicy.Id, 10))
|
||||
logs.Error("CACHE", "remove policy "+strconv.FormatInt(oldPolicy.Id, 10))
|
||||
delete(this.policyMap, oldPolicy.Id)
|
||||
storage, ok := this.storageMap[oldPolicy.Id]
|
||||
if ok {
|
||||
@@ -49,13 +49,13 @@ func (this *Manager) UpdatePolicies(newPolicies []*serverconfigs.HTTPCachePolicy
|
||||
for _, newPolicy := range newPolicies {
|
||||
_, ok := this.policyMap[newPolicy.Id]
|
||||
if !ok {
|
||||
logs.Println("[CACHE]add policy", strconv.FormatInt(newPolicy.Id, 10))
|
||||
logs.Println("CACHE", "add policy "+strconv.FormatInt(newPolicy.Id, 10))
|
||||
}
|
||||
|
||||
// 初始化
|
||||
err := newPolicy.Init()
|
||||
if err != nil {
|
||||
logs.Println("[CACHE]UpdatePolicies: init policy error: " + err.Error())
|
||||
logs.Error("CACHE", "UpdatePolicies: init policy error: "+err.Error())
|
||||
continue
|
||||
}
|
||||
this.policyMap[newPolicy.Id] = newPolicy
|
||||
@@ -67,19 +67,19 @@ func (this *Manager) UpdatePolicies(newPolicies []*serverconfigs.HTTPCachePolicy
|
||||
if !ok {
|
||||
storage := this.NewStorageWithPolicy(policy)
|
||||
if storage == nil {
|
||||
logs.Println("[CACHE]can not find storage type '" + policy.Type + "'")
|
||||
logs.Error("CACHE", "can not find storage type '"+policy.Type+"'")
|
||||
continue
|
||||
}
|
||||
err := storage.Init()
|
||||
if err != nil {
|
||||
logs.Println("[CACHE]UpdatePolicies: init storage failed: " + err.Error())
|
||||
logs.Error("CACHE", "UpdatePolicies: init storage failed: "+err.Error())
|
||||
continue
|
||||
}
|
||||
this.storageMap[policy.Id] = storage
|
||||
} else {
|
||||
// 检查policy是否有变化
|
||||
if !storage.Policy().IsSame(policy) {
|
||||
logs.Println("[CACHE]policy " + strconv.FormatInt(policy.Id, 10) + " changed")
|
||||
logs.Println("CACHE", "policy "+strconv.FormatInt(policy.Id, 10)+" changed")
|
||||
|
||||
// 停止老的
|
||||
storage.Stop()
|
||||
@@ -88,12 +88,12 @@ func (this *Manager) UpdatePolicies(newPolicies []*serverconfigs.HTTPCachePolicy
|
||||
// 启动新的
|
||||
storage := this.NewStorageWithPolicy(policy)
|
||||
if storage == nil {
|
||||
logs.Println("[CACHE]can not find storage type '" + policy.Type + "'")
|
||||
logs.Error("CACHE", "can not find storage type '"+policy.Type+"'")
|
||||
continue
|
||||
}
|
||||
err := storage.Init()
|
||||
if err != nil {
|
||||
logs.Println("[CACHE]UpdatePolicies: init storage failed: " + err.Error())
|
||||
logs.Error("CACHE", "UpdatePolicies: init storage failed: "+err.Error())
|
||||
continue
|
||||
}
|
||||
this.storageMap[policy.Id] = storage
|
||||
|
||||
@@ -6,9 +6,9 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
|
||||
"github.com/TeaOSLab/EdgeNode/internal/logs"
|
||||
"github.com/TeaOSLab/EdgeNode/internal/utils"
|
||||
"github.com/iwind/TeaGo/Tea"
|
||||
"github.com/iwind/TeaGo/logs"
|
||||
"github.com/iwind/TeaGo/types"
|
||||
stringutil "github.com/iwind/TeaGo/utils/string"
|
||||
"io"
|
||||
@@ -81,7 +81,7 @@ func (this *FileStorage) Init() error {
|
||||
}
|
||||
|
||||
cost := time.Since(before).Seconds() * 1000
|
||||
logs.Println("[CACHE]init policy "+strconv.FormatInt(this.policy.Id, 10)+", cost: "+fmt.Sprintf("%.2f", cost)+" ms, count: "+strconv.Itoa(count)+", size: ", fmt.Sprintf("%.3f", float64(size)/1024/1024)+" M")
|
||||
logs.Println("CACHE", "init policy "+strconv.FormatInt(this.policy.Id, 10)+", cost: "+fmt.Sprintf("%.2f", cost)+" ms, count: "+strconv.Itoa(count)+", size: "+fmt.Sprintf("%.3f", float64(size)/1024/1024)+" M")
|
||||
}()
|
||||
|
||||
// 配置
|
||||
@@ -545,7 +545,7 @@ func (this *FileStorage) initList() error {
|
||||
item, err := this.decodeFile(path)
|
||||
if err != nil {
|
||||
if err != ErrNotFound {
|
||||
logs.Println("[CACHE]decode path '" + path + "': " + err.Error())
|
||||
logs.Error("CACHE", "decode path '"+path+"': "+err.Error())
|
||||
}
|
||||
continue
|
||||
}
|
||||
@@ -634,7 +634,7 @@ func (this *FileStorage) purgeLoop() {
|
||||
path := this.hashPath(hash)
|
||||
err := os.Remove(path)
|
||||
if err != nil && !os.IsNotExist(err) {
|
||||
logs.Println("[CACHE]purge '" + path + "' error: " + err.Error())
|
||||
logs.Error("CACHE", "purge '"+path+"' error: "+err.Error())
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user