add Inode test and go fmt
This commit is contained in:
parent
c7ffdfa3b5
commit
e1e9f80bf0
16
disk.go
16
disk.go
|
@ -5,14 +5,14 @@ import (
|
|||
)
|
||||
|
||||
type DiskUsageStat struct {
|
||||
Path string `json:"path"`
|
||||
Total uint64 `json:"total"`
|
||||
Free uint64 `json:"free"`
|
||||
Used uint64 `json:"used"`
|
||||
UsedPercent float64 `json:"usedPercent"`
|
||||
InodesTotal uint64 `json:"inodesTotal"`
|
||||
InodesUsed uint64 `json:"inodesUsed"`
|
||||
InodesFree uint64 `json:"inodesFree"`
|
||||
Path string `json:"path"`
|
||||
Total uint64 `json:"total"`
|
||||
Free uint64 `json:"free"`
|
||||
Used uint64 `json:"used"`
|
||||
UsedPercent float64 `json:"usedPercent"`
|
||||
InodesTotal uint64 `json:"inodesTotal"`
|
||||
InodesUsed uint64 `json:"inodesUsed"`
|
||||
InodesFree uint64 `json:"inodesFree"`
|
||||
InodesUsedPercent float64 `json:"inodesUsedPercent"`
|
||||
}
|
||||
|
||||
|
|
16
disk_test.go
16
disk_test.go
|
@ -48,13 +48,17 @@ func TestDisk_io_counters(t *testing.T) {
|
|||
|
||||
func TestDiskUsageStat_String(t *testing.T) {
|
||||
v := DiskUsageStat{
|
||||
Path: "/",
|
||||
Total: 1000,
|
||||
Free: 2000,
|
||||
Used: 3000,
|
||||
UsedPercent: 50.1,
|
||||
Path: "/",
|
||||
Total: 1000,
|
||||
Free: 2000,
|
||||
Used: 3000,
|
||||
UsedPercent: 50.1,
|
||||
InodesTotal: 4000,
|
||||
InodesUsed: 5000,
|
||||
InodesFree: 6000,
|
||||
InodesUsedPercent: 49.1,
|
||||
}
|
||||
e := `{"path":"/","total":1000,"free":2000,"used":3000,"usedPercent":50.1}`
|
||||
e := `{"path":"/","total":1000,"free":2000,"used":3000,"usedPercent":50.1,"inodesTotal":4000,"inodesUsed":5000,"inodesFree":6000,"inodesUsedPercent":49.1}`
|
||||
if e != fmt.Sprintf("%v", v) {
|
||||
t.Errorf("DiskUsageStat string is invalid: %v", v)
|
||||
}
|
||||
|
|
|
@ -14,11 +14,11 @@ func DiskUsage(path string) (*DiskUsageStat, error) {
|
|||
bsize := stat.Bsize / 512
|
||||
|
||||
ret := &DiskUsageStat{
|
||||
Path: path,
|
||||
Total: (uint64(stat.Blocks) * uint64(bsize)) >> 1,
|
||||
Free: (uint64(stat.Bfree) * uint64(bsize)) >> 1,
|
||||
Path: path,
|
||||
Total: (uint64(stat.Blocks) * uint64(bsize)) >> 1,
|
||||
Free: (uint64(stat.Bfree) * uint64(bsize)) >> 1,
|
||||
InodesTotal: (uint64(stat.Files)),
|
||||
InodesFree: (uint64(stat.Ffree)),
|
||||
InodesFree: (uint64(stat.Ffree)),
|
||||
}
|
||||
|
||||
ret.InodesUsed = (ret.InodesTotal - ret.InodesFree)
|
||||
|
|
Loading…
Reference in New Issue