Skip to content

Commit

Permalink
Merge pull request #1345 from itsties/patch-1
Browse files Browse the repository at this point in the history
[disk][linux] Fix for diskusage Ceph mount
  • Loading branch information
shirou committed Sep 9, 2022
2 parents a63ec01 + f253d81 commit 434cc29
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 12 deletions.
19 changes: 10 additions & 9 deletions disk/disk_unix.go
Expand Up @@ -27,28 +27,29 @@ func UsageWithContext(ctx context.Context, path string) (*UsageStat, error) {
InodesFree: (uint64(stat.Ffree)),
}

ret.Used = (uint64(stat.Blocks) - uint64(stat.Bfree)) * uint64(bsize)

if (ret.Used + ret.Free) == 0 {
ret.UsedPercent = 0
} else {
// We don't use ret.Total to calculate percent.
// see https://github.com/shirou/gopsutil/issues/562
ret.UsedPercent = (float64(ret.Used) / float64(ret.Used+ret.Free)) * 100.0
}

// if could not get InodesTotal, return empty
if ret.InodesTotal < ret.InodesFree {
return ret, nil
}

ret.InodesUsed = (ret.InodesTotal - ret.InodesFree)
ret.Used = (uint64(stat.Blocks) - uint64(stat.Bfree)) * uint64(bsize)

if ret.InodesTotal == 0 {
ret.InodesUsedPercent = 0
} else {
ret.InodesUsedPercent = (float64(ret.InodesUsed) / float64(ret.InodesTotal)) * 100.0
}

if (ret.Used + ret.Free) == 0 {
ret.UsedPercent = 0
} else {
// We don't use ret.Total to calculate percent.
// see https://github.com/shirou/gopsutil/issues/562
ret.UsedPercent = (float64(ret.Used) / float64(ret.Used+ret.Free)) * 100.0
}

return ret, nil
}

Expand Down
4 changes: 2 additions & 2 deletions internal/common/common.go
Expand Up @@ -114,8 +114,8 @@ func ReadLines(filename string) ([]string, error) {
// ReadLinesOffsetN reads contents from file and splits them by new line.
// The offset tells at which line number to start.
// The count determines the number of lines to read (starting from offset):
// n >= 0: at most n lines
// n < 0: whole file
// n >= 0: at most n lines
// n < 0: whole file
func ReadLinesOffsetN(filename string, offset uint, n int) ([]string, error) {
f, err := os.Open(filename)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion net/net_linux.go
Expand Up @@ -161,7 +161,7 @@ var netProtocols = []string{
// If protocols is empty then all protocols are returned, otherwise
// just the protocols in the list are returned.
// Available protocols:
// ip,icmp,icmpmsg,tcp,udp,udplite
// [ip,icmp,icmpmsg,tcp,udp,udplite]
func ProtoCounters(protocols []string) ([]ProtoCountersStat, error) {
return ProtoCountersWithContext(context.Background(), protocols)
}
Expand Down

0 comments on commit 434cc29

Please sign in to comment.