mirror of
https://github.com/TeaOSLab/EdgeNode.git
synced 2025-12-11 04:40:26 +08:00
节点状态中增加缓存用量数据
This commit is contained in:
@@ -138,3 +138,27 @@ func (this *Manager) NewStorageWithPolicy(policy *serverconfigs.HTTPCachePolicy)
|
|||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TotalDiskSize 消耗的磁盘尺寸
|
||||||
|
func (this *Manager) TotalDiskSize() int64 {
|
||||||
|
this.locker.RLock()
|
||||||
|
defer this.locker.RUnlock()
|
||||||
|
|
||||||
|
total := int64(0)
|
||||||
|
for _, storage := range this.storageMap {
|
||||||
|
total += storage.TotalDiskSize()
|
||||||
|
}
|
||||||
|
return total
|
||||||
|
}
|
||||||
|
|
||||||
|
// TotalMemorySize 消耗的内存尺寸
|
||||||
|
func (this *Manager) TotalMemorySize() int64 {
|
||||||
|
this.locker.RLock()
|
||||||
|
defer this.locker.RUnlock()
|
||||||
|
|
||||||
|
total := int64(0)
|
||||||
|
for _, storage := range this.storageMap {
|
||||||
|
total += storage.TotalMemorySize()
|
||||||
|
}
|
||||||
|
return total
|
||||||
|
}
|
||||||
|
|||||||
@@ -496,6 +496,19 @@ func (this *FileStorage) Stop() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TotalDiskSize 消耗的磁盘尺寸
|
||||||
|
func (this *FileStorage) TotalDiskSize() int64 {
|
||||||
|
return atomic.LoadInt64(&this.totalSize)
|
||||||
|
}
|
||||||
|
|
||||||
|
// TotalMemorySize 内存尺寸
|
||||||
|
func (this *FileStorage) TotalMemorySize() int64 {
|
||||||
|
if this.memoryStorage == nil {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
return this.memoryStorage.TotalMemorySize()
|
||||||
|
}
|
||||||
|
|
||||||
// 绝对路径
|
// 绝对路径
|
||||||
func (this *FileStorage) dir() string {
|
func (this *FileStorage) dir() string {
|
||||||
return this.cacheConfig.Dir + "/p" + strconv.FormatInt(this.policy.Id, 10) + "/"
|
return this.cacheConfig.Dir + "/p" + strconv.FormatInt(this.policy.Id, 10) + "/"
|
||||||
|
|||||||
@@ -4,35 +4,41 @@ import (
|
|||||||
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
|
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
|
||||||
)
|
)
|
||||||
|
|
||||||
// 缓存存储接口
|
// StorageInterface 缓存存储接口
|
||||||
type StorageInterface interface {
|
type StorageInterface interface {
|
||||||
// 初始化
|
// Init 初始化
|
||||||
Init() error
|
Init() error
|
||||||
|
|
||||||
// 读取缓存
|
// OpenReader 读取缓存
|
||||||
OpenReader(key string) (Reader, error)
|
OpenReader(key string) (Reader, error)
|
||||||
|
|
||||||
// 打开缓存写入器等待写入
|
// OpenWriter 打开缓存写入器等待写入
|
||||||
OpenWriter(key string, expiredAt int64, status int) (Writer, error)
|
OpenWriter(key string, expiredAt int64, status int) (Writer, error)
|
||||||
|
|
||||||
// 删除某个键值对应的缓存
|
// Delete 删除某个键值对应的缓存
|
||||||
Delete(key string) error
|
Delete(key string) error
|
||||||
|
|
||||||
// 统计缓存
|
// Stat 统计缓存
|
||||||
Stat() (*Stat, error)
|
Stat() (*Stat, error)
|
||||||
|
|
||||||
// 清除所有缓存
|
// TotalDiskSize 消耗的磁盘尺寸
|
||||||
|
TotalDiskSize() int64
|
||||||
|
|
||||||
|
// TotalMemorySize 内存尺寸
|
||||||
|
TotalMemorySize() int64
|
||||||
|
|
||||||
|
// CleanAll 清除所有缓存
|
||||||
CleanAll() error
|
CleanAll() error
|
||||||
|
|
||||||
// 批量删除缓存
|
// Purge 批量删除缓存
|
||||||
Purge(keys []string, urlType string) error
|
Purge(keys []string, urlType string) error
|
||||||
|
|
||||||
// 停止缓存策略
|
// Stop 停止缓存策略
|
||||||
Stop()
|
Stop()
|
||||||
|
|
||||||
// 获取当前存储的Policy
|
// Policy 获取当前存储的Policy
|
||||||
Policy() *serverconfigs.HTTPCachePolicy
|
Policy() *serverconfigs.HTTPCachePolicy
|
||||||
|
|
||||||
// 将缓存添加到列表
|
// AddToList 将缓存添加到列表
|
||||||
AddToList(item *Item)
|
AddToList(item *Item)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -183,6 +183,16 @@ func (this *MemoryStorage) AddToList(item *Item) {
|
|||||||
this.list.Add(hash, item)
|
this.list.Add(hash, item)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TotalDiskSize 消耗的磁盘尺寸
|
||||||
|
func (this *MemoryStorage) TotalDiskSize() int64 {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
// TotalMemorySize 内存尺寸
|
||||||
|
func (this *MemoryStorage) TotalMemorySize() int64 {
|
||||||
|
return atomic.LoadInt64(&this.totalSize)
|
||||||
|
}
|
||||||
|
|
||||||
// 计算Key Hash
|
// 计算Key Hash
|
||||||
func (this *MemoryStorage) hash(key string) uint64 {
|
func (this *MemoryStorage) hash(key string) uint64 {
|
||||||
return xxhash.Sum64String(key)
|
return xxhash.Sum64String(key)
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"github.com/TeaOSLab/EdgeCommon/pkg/nodeconfigs"
|
"github.com/TeaOSLab/EdgeCommon/pkg/nodeconfigs"
|
||||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||||
|
"github.com/TeaOSLab/EdgeNode/internal/caches"
|
||||||
teaconst "github.com/TeaOSLab/EdgeNode/internal/const"
|
teaconst "github.com/TeaOSLab/EdgeNode/internal/const"
|
||||||
"github.com/TeaOSLab/EdgeNode/internal/events"
|
"github.com/TeaOSLab/EdgeNode/internal/events"
|
||||||
"github.com/TeaOSLab/EdgeNode/internal/monitor"
|
"github.com/TeaOSLab/EdgeNode/internal/monitor"
|
||||||
@@ -64,6 +65,8 @@ func (this *NodeStatusExecutor) update() {
|
|||||||
status.ConfigVersion = sharedNodeConfig.Version
|
status.ConfigVersion = sharedNodeConfig.Version
|
||||||
status.IsActive = true
|
status.IsActive = true
|
||||||
status.ConnectionCount = sharedListenerManager.TotalActiveConnections()
|
status.ConnectionCount = sharedListenerManager.TotalActiveConnections()
|
||||||
|
status.CacheTotalDiskSize = caches.SharedManager.TotalDiskSize()
|
||||||
|
status.CacheTotalMemorySize = caches.SharedManager.TotalMemorySize()
|
||||||
|
|
||||||
// 记录监控数据
|
// 记录监控数据
|
||||||
monitor.SharedValueQueue.Add(nodeconfigs.NodeValueItemConnections, maps.Map{
|
monitor.SharedValueQueue.Add(nodeconfigs.NodeValueItemConnections, maps.Map{
|
||||||
|
|||||||
Reference in New Issue
Block a user