监控网页实现
This commit is contained in:
38
backend/internal/monitor/disk_windows.go
Normal file
38
backend/internal/monitor/disk_windows.go
Normal file
@@ -0,0 +1,38 @@
|
||||
//go:build windows
|
||||
|
||||
package monitor
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"golang.org/x/sys/windows"
|
||||
)
|
||||
|
||||
func getDiskSpaceGB() (float64, float64) {
|
||||
wd, err := os.Getwd()
|
||||
if err != nil {
|
||||
return 0, 0
|
||||
}
|
||||
|
||||
vol := filepath.VolumeName(wd)
|
||||
if vol == "" {
|
||||
return 0, 0
|
||||
}
|
||||
root := vol + `\\`
|
||||
|
||||
pathPtr, err := windows.UTF16PtrFromString(root)
|
||||
if err != nil {
|
||||
return 0, 0
|
||||
}
|
||||
|
||||
var freeBytesAvailable uint64
|
||||
var totalBytes uint64
|
||||
var totalFreeBytes uint64
|
||||
if err := windows.GetDiskFreeSpaceEx(pathPtr, &freeBytesAvailable, &totalBytes, &totalFreeBytes); err != nil {
|
||||
return 0, 0
|
||||
}
|
||||
|
||||
const gb = 1024.0 * 1024.0 * 1024.0
|
||||
return float64(totalBytes) / gb, float64(totalFreeBytes) / gb
|
||||
}
|
||||
Reference in New Issue
Block a user