aboutsummaryrefslogtreecommitdiff
path: root/unmaintained
diff options
context:
space:
mode:
authorzouyixiong <zouyixiong@gmail.com>2025-02-18 07:49:11 +0800
committerGitHub <noreply@github.com>2025-02-17 15:49:11 -0800
commit739216189407b15f5a7be5e353a1d0234f674e04 (patch)
treea222d58c90dbcb10f2022959c73fd8bef054bbf7 /unmaintained
parentc2b894276992e8b3a879945d3eb9ff303fe47c74 (diff)
downloadseaweedfs-739216189407b15f5a7be5e353a1d0234f674e04.tar.xz
seaweedfs-739216189407b15f5a7be5e353a1d0234f674e04.zip
fix: The free disk size and percentage are quite different from the output of df -h. (#6550)
* fix: record and delete bucket metrics after inactive * feat: match available disk size with system cmd `dh -h` * feat: move temp test to unmaintained/ --------- Co-authored-by: XYZ <XYZ>
Diffstat (limited to 'unmaintained')
-rw-r--r--unmaintained/disk/disk_status.go57
1 files changed, 57 insertions, 0 deletions
diff --git a/unmaintained/disk/disk_status.go b/unmaintained/disk/disk_status.go
new file mode 100644
index 000000000..e01b16f22
--- /dev/null
+++ b/unmaintained/disk/disk_status.go
@@ -0,0 +1,57 @@
+//go:build !windows && !openbsd && !netbsd && !plan9 && !solaris
+// +build !windows,!openbsd,!netbsd,!plan9,!solaris
+
+package main
+
+import (
+ "log"
+ "syscall"
+)
+
+// go run unmaintained/disk/disk_status.go
+
+type DiskStatus struct {
+ Dir string `protobuf:"bytes,1,opt,name=dir,proto3" json:"dir,omitempty"`
+ All uint64 `protobuf:"varint,2,opt,name=all,proto3" json:"all,omitempty"`
+ Used uint64 `protobuf:"varint,3,opt,name=used,proto3" json:"used,omitempty"`
+ Free uint64 `protobuf:"varint,4,opt,name=free,proto3" json:"free,omitempty"`
+ PercentFree float32 `protobuf:"fixed32,5,opt,name=percent_free,json=percentFree,proto3" json:"percent_free,omitempty"`
+ PercentUsed float32 `protobuf:"fixed32,6,opt,name=percent_used,json=percentUsed,proto3" json:"percent_used,omitempty"`
+ DiskType string `protobuf:"bytes,7,opt,name=disk_type,json=diskType,proto3" json:"disk_type,omitempty"`
+
+ // new fields about availĀ blocks
+ Avail uint64 `protobuf:"varint,4,opt,name=avail,proto3" json:"avail,omitempty"`
+ PercentAvail float32 `protobuf:"fixed32,5,opt,name=percent_avail,json=percentAvail,proto3" json:"percent_avail,omitempty"`
+}
+
+func main() {
+ dirs := []string{"/mnt/sdb", "/mnt/sdc", "/mnt/sdd", "/mnt/sde", "/mnt/sdf", "/mnt/sdg", "/mnt/sdh", "/mnt/sdi", "/mnt/sdj"}
+ // dirs := []string{"/mnt/sdb"}
+ for _, dir := range dirs {
+ disk := &DiskStatus{Dir: dir}
+ fillInDiskStatus(disk)
+
+ // bytes, _ := json.Marshal(disk)
+ // log.Printf("disk status %s", bytes)
+ log.Printf("disk: %s avail: %f free: %f", disk.Dir, disk.PercentAvail, disk.PercentFree)
+ }
+}
+
+func fillInDiskStatus(disk *DiskStatus) {
+ fs := syscall.Statfs_t{}
+ err := syscall.Statfs(disk.Dir, &fs)
+ if err != nil {
+ return
+ }
+
+ disk.All = fs.Blocks * uint64(fs.Bsize)
+ disk.Free = fs.Bfree * uint64(fs.Bsize)
+ disk.Used = disk.All - disk.Free
+ disk.PercentFree = float32((float64(disk.Free) / float64(disk.All)) * 100)
+ disk.PercentUsed = float32((float64(disk.Used) / float64(disk.All)) * 100)
+
+ // avail blocks
+ disk.Avail = fs.Bavail * uint64(fs.Bsize)
+ disk.PercentAvail = float32((float64(disk.Avail) / float64(disk.All)) * 100)
+ return
+}