diff options
| author | Chris Lu <chrislusf@users.noreply.github.com> | 2020-06-02 13:55:39 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-06-02 13:55:39 -0700 |
| commit | fbed2e9026b71c810dd86bd826c9e068e93d3c48 (patch) | |
| tree | a085e2e33851c4d916bef2952abc7cfbfe95ee88 | |
| parent | bc2ec6774d10349143dec326f227a2a809c01731 (diff) | |
| parent | 48f9ff52cf343e235987b542ce5c12e4d1e4c072 (diff) | |
| download | seaweedfs-fbed2e9026b71c810dd86bd826c9e068e93d3c48.tar.xz seaweedfs-fbed2e9026b71c810dd86bd826c9e068e93d3c48.zip | |
Merge pull request #1341 from ekozlov-search/windows_disk_stat
Discs statistics on Windows platform.
| -rw-r--r-- | weed/stats/disk_notsupported.go | 2 | ||||
| -rw-r--r-- | weed/stats/disk_windows.go | 46 |
2 files changed, 47 insertions, 1 deletions
diff --git a/weed/stats/disk_notsupported.go b/weed/stats/disk_notsupported.go index ace662f6a..3d99e6ce7 100644 --- a/weed/stats/disk_notsupported.go +++ b/weed/stats/disk_notsupported.go @@ -1,4 +1,4 @@ -// +build windows openbsd netbsd plan9 solaris +// +build openbsd netbsd plan9 solaris package stats diff --git a/weed/stats/disk_windows.go b/weed/stats/disk_windows.go new file mode 100644 index 000000000..1185e129c --- /dev/null +++ b/weed/stats/disk_windows.go @@ -0,0 +1,46 @@ +package stats + +import ( + "github.com/chrislusf/seaweedfs/weed/pb/volume_server_pb" + "golang.org/x/sys/windows" + "syscall" + "unsafe" +) +var ( + kernel32 = windows.NewLazySystemDLL("Kernel32.dll") + getDiskFreeSpaceEx = kernel32.NewProc("GetDiskFreeSpaceExW") +) + +func fillInDiskStatus(disk *volume_server_pb.DiskStatus) { + + ptr, err := syscall.UTF16PtrFromString(disk.Dir) + + if err != nil { + return + } + var _temp uint64 + /* #nosec */ + r, _, e := syscall.Syscall6( + getDiskFreeSpaceEx.Addr(), + 4, + uintptr(unsafe.Pointer(ptr)), + uintptr(unsafe.Pointer(&disk.Free)), + uintptr(unsafe.Pointer(&disk.All)), + uintptr(unsafe.Pointer(&_temp)), + 0, + 0, + ) + + if r == 0 { + if e != 0 { + return + } + + return + } + 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) + + return +} |
