parsePSIStats parses the specified file for pressure stall information.
(r io.Reader)
| 69 | |
| 70 | // parsePSIStats parses the specified file for pressure stall information. |
| 71 | func parsePSIStats(r io.Reader) (PSIStats, error) { |
| 72 | psiStats := PSIStats{} |
| 73 | |
| 74 | scanner := bufio.NewScanner(r) |
| 75 | for scanner.Scan() { |
| 76 | l := scanner.Text() |
| 77 | prefix := strings.Split(l, " ")[0] |
| 78 | switch prefix { |
| 79 | case "some": |
| 80 | psi := PSILine{} |
| 81 | _, err := fmt.Sscanf(l, fmt.Sprintf("some %s", lineFormat), &psi.Avg10, &psi.Avg60, &psi.Avg300, &psi.Total) |
| 82 | if err != nil { |
| 83 | return PSIStats{}, err |
| 84 | } |
| 85 | psiStats.Some = &psi |
| 86 | case "full": |
| 87 | psi := PSILine{} |
| 88 | _, err := fmt.Sscanf(l, fmt.Sprintf("full %s", lineFormat), &psi.Avg10, &psi.Avg60, &psi.Avg300, &psi.Total) |
| 89 | if err != nil { |
| 90 | return PSIStats{}, err |
| 91 | } |
| 92 | psiStats.Full = &psi |
| 93 | default: |
| 94 | // If we encounter a line with an unknown prefix, ignore it and move on |
| 95 | // Should new measurement types be added in the future we'll simply ignore them instead |
| 96 | // of erroring on retrieval |
| 97 | continue |
| 98 | } |
| 99 | } |
| 100 | |
| 101 | return psiStats, nil |
| 102 | } |
no outgoing calls