| 66 | } |
| 67 | |
| 68 | func parseFileFDStats(filename string) (map[string]string, error) { |
| 69 | file, err := os.Open(filename) |
| 70 | if err != nil { |
| 71 | return nil, err |
| 72 | } |
| 73 | defer file.Close() |
| 74 | |
| 75 | content, err := io.ReadAll(file) |
| 76 | if err != nil { |
| 77 | return nil, err |
| 78 | } |
| 79 | parts := bytes.Split(bytes.TrimSpace(content), []byte("\u0009")) |
| 80 | if len(parts) < 3 { |
| 81 | return nil, fmt.Errorf("unexpected number of file stats in %q", filename) |
| 82 | } |
| 83 | |
| 84 | var fileFDStat = map[string]string{} |
| 85 | // The file-nr proc is only 1 line with 3 values. |
| 86 | fileFDStat["allocated"] = string(parts[0]) |
| 87 | // The second value is skipped as it will always be zero in linux 2.6. |
| 88 | fileFDStat["maximum"] = string(parts[2]) |
| 89 | |
| 90 | return fileFDStat, nil |
| 91 | } |