func blkioThrottle()

in metric/system/cgroup/cgv1/blkio.go [126:207]


func blkioThrottle(path string, blkio *BlockIOSubsystem) error {
	devices := map[DeviceID]*ThrottleDevice{}

	getDevice := func(id DeviceID) *ThrottleDevice {
		td := devices[id]
		if td == nil {
			td = &ThrottleDevice{DeviceID: id}
			devices[id] = td
		}
		return td
	}

	values, err := readBlkioValues(path, "blkio.throttle.io_service_bytes")
	if err != nil {
		return fmt.Errorf("error reading blkio.throttle.io_service_bytes: %w", err)
	}
	if values != nil {
		for id, opValues := range collectOpValues(values) {
			getDevice(id).Bytes = *opValues
		}
	}

	values, err = readBlkioValues(path, "blkio.throttle.io_serviced")
	if err != nil {
		return fmt.Errorf("error reading blkio.throttle.io_serviced: %w", err)
	}
	if values != nil {
		for id, opValues := range collectOpValues(values) {
			getDevice(id).IOs = *opValues
		}
	}

	values, err = readBlkioValues(path, "blkio.throttle.read_bps_device")
	if err != nil {
		return fmt.Errorf("error reading blkio.throttle.read_bps_device: %w", err)
	}
	if len(values) != 0 {
		for _, bv := range values {
			getDevice(bv.DeviceID).ReadLimitBPS = bv.Value
		}
	}

	values, err = readBlkioValues(path, "blkio.throttle.write_bps_device")
	if err != nil {
		return fmt.Errorf("error reading blkio.throttle.write_bps_device: %w", err)
	}
	if len(values) != 0 {
		for _, bv := range values {
			getDevice(bv.DeviceID).WriteLimitBPS = bv.Value
		}
	}

	values, err = readBlkioValues(path, "blkio.throttle.read_iops_device")
	if err != nil {
		return fmt.Errorf("error reading blkio.throttle.read_iops_device: %w", err)
	}
	if len(values) != 0 {
		for _, bv := range values {
			getDevice(bv.DeviceID).ReadLimitIOPS = bv.Value
		}
	}

	values, err = readBlkioValues(path, "blkio.throttle.write_iops_device")
	if err != nil {
		return fmt.Errorf("error reading blkio.throttle.write_iops_device: %w", err)
	}
	if len(values) != 0 {
		for _, bv := range values {
			getDevice(bv.DeviceID).WriteLimitIOPS = bv.Value
		}
	}

	for _, dev := range devices {
		blkio.Total.Bytes += dev.Bytes.Read + dev.Bytes.Write
		blkio.Total.Ios += dev.IOs.Read + dev.IOs.Write
		blkio.Reads.Bytes += dev.Bytes.Read
		blkio.Reads.Ios += dev.IOs.Read
		blkio.Writes.Bytes += dev.Bytes.Write
		blkio.Writes.Ios += dev.IOs.Write
	}
	return nil
}