use of com.emc.storageos.systemservices.impl.healthmonitor.models.CPUStats in project coprhd-controller by CoprHD.
the class NodeStatsExtractor method getDiskStats.
/**
* Get /proc/diskstats data. If "interval" value is > 0 this will get stats again
* after sleep for interval seconds.
*
* @param intervalInSecs interval value in seconds
* @return List of disk stats
*/
public static List<DiskStats> getDiskStats(int intervalInSecs) {
// Getting disk/cpu stats
try {
Map<String, DiskStats> oldDiskDataMap = ProcStats.getDiskStats();
CPUStats oldCPUStats = ProcStats.getCPUStats();
// sleep if needed
Map<String, DiskStats> newDiskDataMap = null;
CPUStats newCPUStats = null;
if (intervalInSecs > 0) {
try {
Thread.sleep(intervalInSecs * 1000);
} catch (InterruptedException e) {
_log.error("Thread Sleep InterrupdtedExcepion: {}", e);
return null;
}
// Getting disk/cpu stats after sleep
newDiskDataMap = ProcStats.getDiskStats();
newCPUStats = ProcStats.getCPUStats();
}
// perform method that will actually perform the calucations.
return getDifferentialDiskStats(oldDiskDataMap, newDiskDataMap, getCPUTimeDeltaMS(oldCPUStats, newCPUStats));
} catch (Exception e) {
_log.error("Error occurred while getting disk stats: {}", e);
}
return null;
}
use of com.emc.storageos.systemservices.impl.healthmonitor.models.CPUStats in project coprhd-controller by CoprHD.
the class ProcStats method getCPUStats.
/**
* Retrieves CPU stats from /proc/stat file.
*/
public static CPUStats getCPUStats() throws IOException, SyssvcInternalException {
String[] fileData = FileReadUtil.readLines(PROC_STAT);
for (String line : fileData) {
if (line != null && line.startsWith("cpu")) {
String[] stats = line.trim().split(SPACE_VALUE);
UnsignedLong systemMode = UnsignedLong.valueOf(stats[3]);
if (stats.length > 7) {
systemMode = systemMode.plus(UnsignedLong.valueOf(stats[6]).plus(UnsignedLong.valueOf(stats[7])));
}
return new CPUStats(UnsignedLong.valueOf(stats[1]).plus(UnsignedLong.valueOf(stats[2])), systemMode, UnsignedLong.valueOf(stats[4]), UnsignedLong.valueOf(stats[5]));
}
}
throw SyssvcException.syssvcExceptions.syssvcInternalError("CPU stats not found.");
}
use of com.emc.storageos.systemservices.impl.healthmonitor.models.CPUStats in project coprhd-controller by CoprHD.
the class ProcStatsTest method testCPUStats.
@Test
public void testCPUStats() {
try {
CPUStats cpuStats = ProcStats.getCPUStats();
Assert.assertTrue(cpuStats.getUserMode().compareTo(UnsignedLong.ZERO) > 0);
} catch (Exception e) {
Assert.fail();
}
}
Aggregations