mirror of
https://github.com/featurebasedb/featurebase.git
synced 2026-09-12 23:51:03 +00:00
Move disk capacity lookup to gopsutil wrapper package
This commit is contained in:
parent
6a298590be
commit
7a32eadc64
3 changed files with 18 additions and 4 deletions
5
api.go
5
api.go
|
|
@ -38,7 +38,6 @@ import (
|
|||
"github.com/pilosa/pilosa/v2/stats"
|
||||
"github.com/pilosa/pilosa/v2/tracing"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/shirou/gopsutil/disk"
|
||||
"golang.org/x/sync/errgroup"
|
||||
)
|
||||
|
||||
|
|
@ -847,11 +846,9 @@ func (api *API) Usage(ctx context.Context, remote bool) (map[string]NodeUsage, e
|
|||
totalSize += indexSizes[file.Name()]
|
||||
}
|
||||
|
||||
usageStats, err := disk.Usage("/")
|
||||
capacity := usageStats.Total
|
||||
capacity, err := api.server.systemInfo.DiskCapacity(api.server.dataDir)
|
||||
|
||||
if err != nil {
|
||||
capacity = uint64(0)
|
||||
api.server.logger.Printf("failed to get disk capacity: %s", err)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -275,6 +275,7 @@ type SystemInfo interface {
|
|||
CPUCores() (physical int, logical int, err error)
|
||||
CPUMHz() (int, error)
|
||||
CPUArch() string
|
||||
DiskCapacity(string) (uint64, error)
|
||||
}
|
||||
|
||||
// newNopSystemInfo creates a no-op implementation of SystemInfo.
|
||||
|
|
@ -345,3 +346,8 @@ func (n *nopSystemInfo) CPUMHz() (int, error) {
|
|||
func (n *nopSystemInfo) CPUCores() (physical, logical int, err error) {
|
||||
return 0, 0, nil
|
||||
}
|
||||
|
||||
// DiskCapacity returns the disk capacity
|
||||
func (n *nopSystemInfo) DiskCapacity(path string) (uint64, error) {
|
||||
return 0, nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@ import (
|
|||
|
||||
"github.com/pilosa/pilosa/v2"
|
||||
"github.com/shirou/gopsutil/cpu"
|
||||
"github.com/shirou/gopsutil/disk"
|
||||
"github.com/shirou/gopsutil/host"
|
||||
"github.com/shirou/gopsutil/mem"
|
||||
)
|
||||
|
|
@ -243,6 +244,16 @@ func (s *systemInfo) CPUCores() (physical, logical int, err error) {
|
|||
return s.cpuPhysicalCores, s.cpuLogicalCores, nil
|
||||
}
|
||||
|
||||
// DiskCapacity returns the disk capacity.
|
||||
func (s *systemInfo) DiskCapacity(path string) (uint64, error) {
|
||||
diskInfo, err := disk.Usage(path)
|
||||
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return diskInfo.Total, nil
|
||||
}
|
||||
|
||||
// NewSystemInfo is a constructor for the gopsutil implementation of SystemInfo.
|
||||
func NewSystemInfo() *systemInfo {
|
||||
return &systemInfo{}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue