日常查询由mysql改为clickhouse
This commit is contained in:
@@ -4,20 +4,9 @@ package fsutils
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeNode/internal/utils/fasttime"
|
||||
"golang.org/x/sys/unix"
|
||||
"sync"
|
||||
)
|
||||
|
||||
// StatDevice device contains the path
|
||||
func StatDevice(path string) (*StatResult, error) {
|
||||
var stat = &unix.Statfs_t{}
|
||||
err := unix.Statfs(path, stat)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return NewStatResult(stat), nil
|
||||
}
|
||||
|
||||
var locker = &sync.RWMutex{}
|
||||
var cacheMap = map[string]*StatResult{} // path => StatResult
|
||||
|
||||
@@ -44,38 +33,3 @@ func StatDeviceCache(path string) (*StatResult, error) {
|
||||
cacheMap[path] = stat
|
||||
return stat, nil
|
||||
}
|
||||
|
||||
type StatResult struct {
|
||||
rawStat *unix.Statfs_t
|
||||
blockSize uint64
|
||||
|
||||
updatedAt int64
|
||||
}
|
||||
|
||||
func NewStatResult(rawStat *unix.Statfs_t) *StatResult {
|
||||
var blockSize = rawStat.Bsize
|
||||
if blockSize < 0 {
|
||||
blockSize = 0
|
||||
}
|
||||
|
||||
return &StatResult{
|
||||
rawStat: rawStat,
|
||||
blockSize: uint64(blockSize),
|
||||
updatedAt: fasttime.Now().Unix(),
|
||||
}
|
||||
}
|
||||
|
||||
func (this *StatResult) FreeSize() uint64 {
|
||||
return this.rawStat.Bfree * this.blockSize
|
||||
}
|
||||
|
||||
func (this *StatResult) TotalSize() uint64 {
|
||||
return this.rawStat.Blocks * this.blockSize
|
||||
}
|
||||
|
||||
func (this *StatResult) UsedSize() uint64 {
|
||||
if this.rawStat.Bfree <= this.rawStat.Blocks {
|
||||
return (this.rawStat.Blocks - this.rawStat.Bfree) * this.blockSize
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user