Skip to content

Commit

Permalink
#1061 Fix transferTime in WindowsDisks by using 1-%Idle (#1063)
Browse files Browse the repository at this point in the history
* Fix transferTime in WindowsDisks by using 1-%Idle - transferTime should be set to 0 if no value is detected
  • Loading branch information
Space2Man authored and dbwiddis committed Dec 17, 2019
1 parent 7c809b6 commit 97da0a4
Showing 1 changed file with 7 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ enum PhysicalDiskProperty implements PdhCounterWildcardProperty {
DISKWRITESPERSEC("Disk Writes/sec"), //
DISKWRITEBYTESPERSEC("Disk Write Bytes/sec"), //
CURRENTDISKQUEUELENGTH("Current Disk Queue Length"), //
PERCENTDISKTIME("% Disk Time");
PERCENTIDLETIME("% Idle Time");

private final String counter;

Expand Down Expand Up @@ -157,7 +157,7 @@ public static boolean updateDiskStats(HWDiskStore diskStore) {
diskStore.setWrites(stats.writeMap.getOrDefault(index, 0L));
diskStore.setWriteBytes(stats.writeByteMap.getOrDefault(index, 0L));
diskStore.setCurrentQueueLength(stats.queueLengthMap.getOrDefault(index, 0L));
diskStore.setTransferTime(stats.xferTimeMap.getOrDefault(index, 0L));
diskStore.setTransferTime(stats.timeStamp-stats.idleTimeMap.getOrDefault(index, stats.timeStamp));
diskStore.setTimeStamp(stats.timeStamp);
return true;
} else {
Expand Down Expand Up @@ -189,7 +189,7 @@ public HWDiskStore[] getDisks() {
ds.setWrites(stats.writeMap.getOrDefault(index, 0L));
ds.setWriteBytes(stats.writeByteMap.getOrDefault(index, 0L));
ds.setCurrentQueueLength(stats.queueLengthMap.getOrDefault(index, 0L));
ds.setTransferTime(stats.xferTimeMap.getOrDefault(index, 0L));
ds.setTransferTime(stats.timeStamp-stats.idleTimeMap.getOrDefault(index, stats.timeStamp));
ds.setTimeStamp(stats.timeStamp);
ds.setSize(WmiUtil.getUint64(vals, DiskDriveProperty.SIZE, i));
// Get partitions
Expand Down Expand Up @@ -228,10 +228,10 @@ private static DiskStats queryReadWriteStats(String index) {
List<Long> writeList = valueMap.get(PhysicalDiskProperty.DISKWRITESPERSEC);
List<Long> writeByteList = valueMap.get(PhysicalDiskProperty.DISKWRITEBYTESPERSEC);
List<Long> queueLengthList = valueMap.get(PhysicalDiskProperty.CURRENTDISKQUEUELENGTH);
List<Long> xferTimeList = valueMap.get(PhysicalDiskProperty.PERCENTDISKTIME);
List<Long> idleTimeList = valueMap.get(PhysicalDiskProperty.PERCENTIDLETIME);

if (instances.isEmpty() || readList == null || readByteList == null || writeList == null
|| writeByteList == null || queueLengthList == null || xferTimeList == null) {
|| writeByteList == null || queueLengthList == null || idleTimeList == null) {
return stats;
}
for (int i = 0; i < instances.size(); i++) {
Expand All @@ -245,7 +245,7 @@ private static DiskStats queryReadWriteStats(String index) {
stats.writeMap.put(name, writeList.get(i));
stats.writeByteMap.put(name, writeByteList.get(i));
stats.queueLengthMap.put(name, queueLengthList.get(i));
stats.xferTimeMap.put(name, xferTimeList.get(i) / 10_000L);
stats.idleTimeMap.put(name, idleTimeList.get(i) / 10_000L);
}
return stats;
}
Expand Down Expand Up @@ -326,7 +326,7 @@ private static final class DiskStats {
private final Map<String, Long> writeMap = new HashMap<>();
private final Map<String, Long> writeByteMap = new HashMap<>();
private final Map<String, Long> queueLengthMap = new HashMap<>();
private final Map<String, Long> xferTimeMap = new HashMap<>();
private final Map<String, Long> idleTimeMap = new HashMap<>();
private long timeStamp;
}

Expand Down

0 comments on commit 97da0a4

Please sign in to comment.