ssh_crawler/stat/disk_free.go
insanity 1552f4eaba ing
2017-10-23 14:31:04 +09:00

49 lines
791 B
Go

package stat
import (
"io"
"bufio"
"strings"
)
type DiskFreeStat struct {
filesystem,
size,
used,
available,
usePerc,
mountedOn string
}
func (diskFree DiskFreeStat) Command() string {
return "df -k"
}
func (diskio DiskFreeStat) Parse(r io.Reader) ([]DiskFreeStat, error) {
var scanner = bufio.NewScanner(r)
var stats = []DiskFreeStat{}
scanner.Scan()
for scanner.Scan() {
parts := strings.Fields(scanner.Text())
stats = append(stats, DiskFreeStat{
filesystem: parts[0],
size: parts[1],
used: parts[2],
available: parts[3],
usePerc: removePercUnit(parts[4]),
mountedOn: parts[5],
})
}
return stats, scanner.Err()
}
func removePercUnit(str string) string {
if !strings.HasSuffix(str, "%"){
return str
}
str = str[:len(str)-1]
return str
}