Created
February 13, 2017 04:22
-
-
Save davidradernj/0db7e067d822566d9059a8426d3ff6ba to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//try to debug weird filesystem size reported in docker container for cockroachdb | |
package main | |
import "fmt" | |
import "strconv" | |
import "github.com/elastic/gosigar" | |
import "syscall" | |
func getReadableFileSize(inbytes int64) string { | |
i := 0 | |
byteUnits := [9]string{" B", " kB", " MB", " GB", " TB", "PB", "EB", "ZB", "YB"} | |
for inbytes > 1024 { | |
inbytes = inbytes / 1024 | |
i += 1 | |
} | |
return strconv.Itoa(int(inbytes)) + byteUnits[i] | |
} | |
func getFSU(path string) error { | |
stat := syscall.Statfs_t{} | |
err := syscall.Statfs(path, &stat) | |
if err != nil { | |
return err | |
} | |
fmt.Println("Bsize: " + strconv.FormatUint(uint64(stat.Bsize), 10)) | |
fmt.Println("Bfree: " + strconv.FormatUint(stat.Bfree, 10)) | |
fmt.Println("Bavail: " + strconv.FormatUint(stat.Bavail, 10)) | |
fmt.Println("Blocks: " + strconv.FormatUint(stat.Blocks, 10)) | |
return nil | |
} | |
func main() { | |
fileSystemUsage := gosigar.FileSystemUsage{} | |
fileSystemUsage.Get(".") | |
fsuTotal := int64(fileSystemUsage.Total) | |
fsuAvail := int64(fileSystemUsage.Avail) | |
fmt.Println(fsuTotal) | |
fmt.Println(fsuAvail) | |
fmt.Println(getReadableFileSize(fsuTotal)) | |
fmt.Println(getReadableFileSize(fsuAvail)) | |
fmt.Println("FSU for /:") | |
getFSU("/") | |
fmt.Println("FSU for .:") | |
getFSU(".") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment