Skip to content

Commit

Permalink
changing the output of FileSystemUsage from Bytes to MB (Author: Shiv…
Browse files Browse the repository at this point in the history
… Shankar Singh)
  • Loading branch information
lokesh.balla committed Apr 19, 2020
1 parent 7aef336 commit 4530041
Showing 1 changed file with 24 additions and 5 deletions.
29 changes: 24 additions & 5 deletions sigar_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,36 @@ import (

"golang.org/x/sys/unix"
)

//func (self *FileSystemUsage) Get(path string) error {
// stat := syscall.Statfs_t{}
// err := syscall.Statfs(path, &stat)
// if err != nil {
// return err
// }
//
// bsize := stat.Bsize / 512
//
// self.Total = (uint64(stat.Blocks) * uint64(bsize)) >> 1
// self.Free = (uint64(stat.Bfree) * uint64(bsize)) >> 1
// self.Avail = (uint64(stat.Bavail) * uint64(bsize)) >> 1
// self.Used = self.Total - self.Free
// self.Files = stat.Files
// self.FreeFiles = stat.Ffree
//
// return nil
//}
func (self *FileSystemUsage) Get(path string) error {
stat := syscall.Statfs_t{}
err := syscall.Statfs(path, &stat)
if err != nil {
return err
}

self.Total = uint64(stat.Blocks) * uint64(stat.Bsize)
self.Free = uint64(stat.Bfree) * uint64(stat.Bsize)
self.Avail = uint64(stat.Bavail) * uint64(stat.Bsize)
bsize := stat.Bsize / 1024

self.Total = uint64(stat.Blocks) * uint64(bsize)
self.Free = uint64(stat.Bfree) * uint64(bsize)
self.Avail = uint64(stat.Bavail) * uint64(bsize)
self.Used = self.Total - self.Free
self.Files = stat.Files
self.FreeFiles = uint64(stat.Ffree)
Expand Down Expand Up @@ -66,4 +85,4 @@ func getResourceUsage(who int) (unix.Rusage, error) {

func convertRtimeToDur(t unix.Timeval) time.Duration {
return time.Duration(t.Nano())
}
}

0 comments on commit 4530041

Please sign in to comment.