aboutsummaryrefslogtreecommitdiff
path: root/weed/topology
diff options
context:
space:
mode:
Diffstat (limited to 'weed/topology')
-rw-r--r--weed/topology/volume_layout.go29
-rw-r--r--weed/topology/volume_location_list.go14
2 files changed, 43 insertions, 0 deletions
diff --git a/weed/topology/volume_layout.go b/weed/topology/volume_layout.go
index 8c0a75140..b6044e29f 100644
--- a/weed/topology/volume_layout.go
+++ b/weed/topology/volume_layout.go
@@ -5,6 +5,7 @@ import (
"fmt"
"math/rand"
"sync"
+ "time"
"github.com/chrislusf/seaweedfs/weed/glog"
"github.com/chrislusf/seaweedfs/weed/storage"
@@ -22,6 +23,12 @@ type VolumeLayout struct {
accessLock sync.RWMutex
}
+type VolumeLayoutStats struct {
+ TotalSize uint64
+ UsedSize uint64
+ FileCount uint64
+}
+
func NewVolumeLayout(rp *storage.ReplicaPlacement, ttl *storage.TTL, volumeSizeLimit uint64) *VolumeLayout {
return &VolumeLayout{
rp: rp,
@@ -265,3 +272,25 @@ func (vl *VolumeLayout) ToMap() map[string]interface{} {
//m["locations"] = vl.vid2location
return m
}
+
+func (vl *VolumeLayout) Stats() *VolumeLayoutStats {
+ vl.accessLock.RLock()
+ defer vl.accessLock.RUnlock()
+
+ ret := &VolumeLayoutStats{}
+
+ freshThreshold := time.Now().Unix() - 60
+
+ for vid, vll := range vl.vid2location {
+ size, fileCount := vll.Stats(vid, freshThreshold)
+ ret.FileCount += uint64(fileCount)
+ ret.UsedSize += size
+ if vl.readonlyVolumes[vid] {
+ ret.TotalSize += size
+ } else {
+ ret.TotalSize += vl.volumeSizeLimit
+ }
+ }
+
+ return ret
+}
diff --git a/weed/topology/volume_location_list.go b/weed/topology/volume_location_list.go
index d5eaf5e92..8d5881333 100644
--- a/weed/topology/volume_location_list.go
+++ b/weed/topology/volume_location_list.go
@@ -2,6 +2,8 @@ package topology
import (
"fmt"
+
+ "github.com/chrislusf/seaweedfs/weed/storage"
)
type VolumeLocationList struct {
@@ -63,3 +65,15 @@ func (dnll *VolumeLocationList) Refresh(freshThreshHold int64) {
dnll.list = l
}
}
+
+func (dnll *VolumeLocationList) Stats(vid storage.VolumeId, freshThreshHold int64) (size uint64, fileCount int) {
+ for _, dnl := range dnll.list {
+ if dnl.LastSeen < freshThreshHold {
+ vinfo, err := dnl.GetVolumesById(vid)
+ if err == nil {
+ return vinfo.Size - vinfo.DeletedByteCount, vinfo.FileCount - vinfo.DeleteCount
+ }
+ }
+ }
+ return 0, 0
+}