@@ -64,7 +64,8 @@ func ConvertUnsignedBytesToMB(byteSize uint64) int64 {
64
64
}
65
65
66
66
// ParseMemFree parses the output of the `free -m` command
67
- func ParseMemFree (out string ) (int64 , error ) {
67
+ // returns: total, available
68
+ func ParseMemFree (out string ) (int64 , int64 , error ) {
68
69
// total used free shared buff/cache available
69
70
//Mem: 1987 706 194 1 1086 1173
70
71
//Swap: 0 0 0
@@ -74,18 +75,23 @@ func ParseMemFree(out string) (int64, error) {
74
75
parsedLine := strings .Fields (line )
75
76
t , err := strconv .ParseInt (parsedLine [1 ], 10 , 64 )
76
77
if err != nil {
77
- return 0 , err
78
+ return 0 , 0 , err
79
+ }
80
+ a , err := strconv .ParseInt (parsedLine [6 ], 10 , 64 )
81
+ if err != nil {
82
+ return 0 , 0 , err
78
83
}
79
84
m := strings .Trim (parsedLine [0 ], ":" )
80
85
if m == "Mem" {
81
- return t , nil
86
+ return t , a , nil
82
87
}
83
88
}
84
- return 0 , nil
89
+ return 0 , 0 , nil
85
90
}
86
91
87
92
// ParseDiskFree parses the output of the `df -m` command
88
- func ParseDiskFree (out string ) (int64 , error ) {
93
+ // returns: total, available
94
+ func ParseDiskFree (out string ) (int64 , int64 , error ) {
89
95
// Filesystem 1M-blocks Used Available Use% Mounted on
90
96
// /dev/sda1 39643 3705 35922 10% /
91
97
outlines := strings .Split (out , "\n " )
@@ -94,14 +100,18 @@ func ParseDiskFree(out string) (int64, error) {
94
100
parsedLine := strings .Fields (line )
95
101
t , err := strconv .ParseInt (parsedLine [1 ], 10 , 64 )
96
102
if err != nil {
97
- return 0 , err
103
+ return 0 , 0 , err
104
+ }
105
+ a , err := strconv .ParseInt (parsedLine [3 ], 10 , 64 )
106
+ if err != nil {
107
+ return 0 , 0 , err
98
108
}
99
109
m := parsedLine [5 ]
100
110
if m == "/" {
101
- return t , nil
111
+ return t , a , nil
102
112
}
103
113
}
104
- return 0 , nil
114
+ return 0 , 0 , nil
105
115
}
106
116
107
117
// GetBinaryDownloadURL returns a suitable URL for the platform
0 commit comments