Initial Proxmox dashboard with host and guest metrics
This commit is contained in:
29
storage.go
Normal file
29
storage.go
Normal file
@@ -0,0 +1,29 @@
|
||||
package main
|
||||
|
||||
import "syscall"
|
||||
|
||||
type StorageMetrics struct {
|
||||
Mountpoint string `json:"mountpoint"`
|
||||
TotalBytes uint64 `json:"totalBytes"`
|
||||
UsedBytes uint64 `json:"usedBytes"`
|
||||
FreeBytes uint64 `json:"freeBytes"`
|
||||
UsagePercent float64 `json:"usagePercent"`
|
||||
}
|
||||
|
||||
func readStorageMetrics(path string) (StorageMetrics, error) {
|
||||
var stat syscall.Statfs_t
|
||||
if err := syscall.Statfs(path, &stat); err != nil {
|
||||
return StorageMetrics{}, err
|
||||
}
|
||||
total := stat.Blocks * uint64(stat.Bsize)
|
||||
free := stat.Bavail * uint64(stat.Bsize)
|
||||
used := total - free
|
||||
var percent float64
|
||||
if total > 0 {
|
||||
percent = float64(used) / float64(total) * 100
|
||||
}
|
||||
return StorageMetrics{
|
||||
Mountpoint: path, TotalBytes: total, UsedBytes: used,
|
||||
FreeBytes: free, UsagePercent: percent,
|
||||
}, nil
|
||||
}
|
||||
Reference in New Issue
Block a user