func ioCounters()

in metric/system/diskio/diskstat_windows_helper.go [54:90]


func ioCounters(names ...string) (map[string]disk.IOCountersStat, error) {
	if err := enablePerformanceCounters(); err != nil {
		return nil, err
	}
	logicalDisks, err := getLogicalDriveStrings()
	if err != nil || len(logicalDisks) == 0 {
		return nil, err
	}
	ret := make(map[string]disk.IOCountersStat, len(logicalDisks))
	for _, drive := range logicalDisks {
		// not get _Total or Harddrive
		if len(drive.Name) > 3 {
			continue
		}
		// filter by included devices
		if len(names) > 0 && !containsDrive(names, drive.Name) {
			continue
		}
		var counter diskPerformance
		err = ioCounter(drive.UNCPath, &counter)
		if err != nil {
			logp.Err("Could not return any performance counter values for %s .Error: %v", drive.UNCPath, err)
			continue
		}
		ret[drive.Name] = disk.IOCountersStat{
			Name:       drive.Name,
			ReadCount:  uint64(counter.ReadCount),
			WriteCount: uint64(counter.WriteCount),
			ReadBytes:  uint64(counter.BytesRead),
			WriteBytes: uint64(counter.BytesWritten),
			// Ticks (which is equal to 100 nanoseconds) will be converted to milliseconds for consistency reasons for both ReadTime and WriteTime (https://docs.microsoft.com/en-us/dotnet/api/system.timespan.ticks?redirectedfrom=MSDN&view=netframework-4.8#remarks)
			ReadTime:  uint64(counter.ReadTime / 10000),
			WriteTime: uint64(counter.WriteTime / 10000),
		}
	}
	return ret, nil
}