Search in sources :

Example 21 with UnsignedLong

use of com.google.common.primitives.UnsignedLong 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)

Aggregations

UnsignedLong (com.google.common.primitives.UnsignedLong)21 Test (org.junit.Test)8 BigInteger (java.math.BigInteger)4 InOrder (org.mockito.InOrder)3 YangInstanceIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)3 MapEntryNode (org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode)3 NormalizedNode (org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode)3 DataTreeSnapshot (org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeSnapshot)3 ArrayList (java.util.ArrayList)2 ClientIdentifier (org.opendaylight.controller.cluster.access.concepts.ClientIdentifier)2 TransactionIdentifier (org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier)2 CommitTransactionPayload (org.opendaylight.controller.cluster.datastore.persisted.CommitTransactionPayload)2 DataTreeCandidateTip (org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidateTip)2 CPUStats (com.emc.storageos.systemservices.impl.healthmonitor.models.CPUStats)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 Optional (java.util.Optional)1 Nullable (javax.annotation.Nullable)1 ArgumentTypeException (org.matheclipse.core.eval.exception.ArgumentTypeException)1 IExpr (org.matheclipse.core.interfaces.IExpr)1