func getIOData()

in metric/system/process/process_linux_common.go [342:378]


func getIOData(hostfs resolve.Resolver, pid int) (ProcIOInfo, error) {
	state := ProcIOInfo{}
	path := hostfs.Join("proc", strconv.Itoa(pid), "io")
	data, err := os.ReadFile(path)
	if err != nil {
		return state, fmt.Errorf("error fetching IO metrics: %w", err)
	}

	for _, metric := range strings.Split(string(data), "\n") {
		raw := strings.Split(metric, ": ")
		if len(raw) < 2 {
			continue
		}
		value, err := strconv.ParseUint(raw[1], 10, 64)
		if err != nil {
			return state, fmt.Errorf("error converting counters '%s' in io stat file: %w", raw, err)
		}

		switch raw[0] {
		case "rchar":
			state.ReadChar = opt.UintWith(value)
		case "wchar":
			state.WriteChar = opt.UintWith(value)
		case "syscr":
			state.ReadSyscalls = opt.UintWith(value)
		case "syscw":
			state.WriteSyscalls = opt.UintWith(value)
		case "read_bytes":
			state.ReadBytes = opt.UintWith(value)
		case "write_bytes":
			state.WriteBytes = opt.UintWith(value)
		case "cancelled_write_bytes":
			state.CancelledWriteBytes = opt.UintWith(value)
		}
	}
	return state, nil
}