package pkg import ( "regexp" "github.rackspace.com/gorax/tools/util" ) var dfUtilRegex = regexp.MustCompile(`(\S+)\s+([0-9]+\S+)\s+([0-9]+\S*)\s+([0-9]+\S+)\s+([0-9]+)%\s+(\S+)`) type ( DfSpace struct { Df []FileSpace `json:"df"` } FileSpace struct { FileSys string `json:"filesystem"` Size string `json:"size"` Used string `json:"used"` Avail string `json:"avail"` UsePer int `json:"use%"` Mount string `json:"mount"` } DfInodes struct { Df []*FileInode `json:"df_inodes"` } FileInode struct { FileSys string `json:"filesystem"` Inodes string `json:"inodes"` Iused string `json:"iused"` Ifree string `json:"ifree"` IusePer int `json:"iuse"` Mount string `json:"mount"` } ) func ParseDfSpace(s string) (d DfSpace) { for _, r := range dfUtilRegex.FindAllStringSubmatch(s, -1) { d.Df = append(d.Df, FileSpace{ FileSys: r[1], Size: r[2], Used: r[3], Avail: r[4], UsePer: util.Atoi(r[5]), Mount: r[6], }) } return } func (d *DfInodes) Parse(s string) { for _, r := range dfUtilRegex.FindAllStringSubmatch(s, -1) { d.Df = append(d.Df, &FileInode{ FileSys: r[1], Inodes: r[2], Iused: r[3], Ifree: r[4], IusePer: util.Atoi(r[5]), Mount: r[6], }) } }