Search in sources :

Example 1 with CPUStats

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;
}
Also used : DiskStats(com.emc.vipr.model.sys.healthmonitor.DiskStats) CPUStats(com.emc.storageos.systemservices.impl.healthmonitor.models.CPUStats) SyssvcException(com.emc.storageos.systemservices.exceptions.SyssvcException)

Example 2 with CPUStats

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.");
}
Also used : CPUStats(com.emc.storageos.systemservices.impl.healthmonitor.models.CPUStats) UnsignedLong(com.google.common.primitives.UnsignedLong)

Example 3 with CPUStats

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();
    }
}
Also used : CPUStats(com.emc.storageos.systemservices.impl.healthmonitor.models.CPUStats) Test(org.junit.Test)

Aggregations

CPUStats (com.emc.storageos.systemservices.impl.healthmonitor.models.CPUStats)3 SyssvcException (com.emc.storageos.systemservices.exceptions.SyssvcException)1 DiskStats (com.emc.vipr.model.sys.healthmonitor.DiskStats)1 UnsignedLong (com.google.common.primitives.UnsignedLong)1 Test (org.junit.Test)1