Gets uint64 parsed content of single value cgroup stat file
(filePath string)
| 265 | |
| 266 | // Gets uint64 parsed content of single value cgroup stat file |
| 267 | func getStatFileContentUint64(filePath string) uint64 { |
| 268 | f, err := os.Open(filePath) |
| 269 | if err != nil { |
| 270 | return 0 |
| 271 | } |
| 272 | defer f.Close() |
| 273 | |
| 274 | // We expect an unsigned 64 bit integer, or a "max" string |
| 275 | // in some cases. |
| 276 | buf := make([]byte, 32) |
| 277 | n, err := f.Read(buf) |
| 278 | if err != nil { |
| 279 | return 0 |
| 280 | } |
| 281 | |
| 282 | trimmed := strings.TrimSpace(string(buf[:n])) |
| 283 | if trimmed == "max" { |
| 284 | return math.MaxUint64 |
| 285 | } |
| 286 | |
| 287 | res, err := parseUint(trimmed, 10, 64) |
| 288 | if err != nil { |
| 289 | log.L.Errorf("unable to parse %q as a uint from Cgroup file %q", trimmed, filePath) |
| 290 | return res |
| 291 | } |
| 292 | |
| 293 | return res |
| 294 | } |
| 295 | |
| 296 | // getKVStatsFileContentUint64 gets uint64 parsed content of key-value cgroup stat file |
| 297 | func getKVStatsFileContentUint64(filePath string, propertyName string) uint64 { |
searching dependent graphs…