use of com.emc.vipr.model.sys.healthmonitor.DiskStats in project coprhd-controller by CoprHD.
the class ProcStats method getDiskStats.
/**
* Reads the /proc/diskstats data and builds a map using the desired counters.
*
* @return Map with disk id as key.
*/
public static Map<String, DiskStats> getDiskStats() throws IOException, SyssvcInternalException {
Map<String, DiskStats> diskStatsMap = new HashMap<String, DiskStats>();
String[] fileData = FileReadUtil.readLines(DISK_STATS);
for (String line : fileData) {
String[] diskStatArray = line.trim().split(SPACE_VALUE);
if (!ACCEPTABLE_DISK_IDS.contains(diskStatArray[2])) {
continue;
}
// verify if disk stats array has 13 elements
if (diskStatArray.length < 13) {
throw SyssvcException.syssvcExceptions.syssvcInternalError("Disk stats file is invalid.");
}
DiskStats diskStats = new DiskStats(diskStatArray[2], Long.parseLong(diskStatArray[3]), Long.parseLong(diskStatArray[5]), Long.parseLong(diskStatArray[6]), Long.parseLong(diskStatArray[7]), Long.parseLong(diskStatArray[9]), Long.parseLong(diskStatArray[10]), Long.parseLong(diskStatArray[12]));
diskStatsMap.put(diskStats.getDiskId(), diskStats);
}
return diskStatsMap;
}
use of com.emc.vipr.model.sys.healthmonitor.DiskStats 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.vipr.model.sys.healthmonitor.DiskStats in project coprhd-controller by CoprHD.
the class NodeStatsExtractor method getDifferentialDiskStats.
/**
* This methods does the work of calculating the diskstats.
* calculated values: read/sec, write/sec, read_sec/sec, write_sec/sec
* avg_wait, svc_time, %util.
*
* @param oldDiskDataMap disk data values collected during initial run
* @param newDiskDataMap disk data values collected after 2s
*/
private static List<DiskStats> getDifferentialDiskStats(Map<String, DiskStats> oldDiskDataMap, Map<String, DiskStats> newDiskDataMap, double deltaMS) {
List<DiskStats> diskStatsList = new ArrayList<DiskStats>();
// iterate though initial map as driver for getting data from the
// compare map and determining the average per second;
DecimalFormat decimalFormat = new DecimalFormat("#####0.00");
for (Map.Entry<String, DiskStats> entry : oldDiskDataMap.entrySet()) {
String diskId = entry.getKey();
DiskStats oldStats = entry.getValue();
DiskStats newStats = null;
if (newDiskDataMap != null && newDiskDataMap.get(diskId) != null) {
newStats = newDiskDataMap.get(diskId);
}
DiskStats diffStats = getDifference(oldStats, newStats);
// number of requests
double numOfIOs = diffStats.getNumberOfReads() + diffStats.getNumberOfWrites();
// await
double wait = numOfIOs > 0 ? (diffStats.getReadTicks() + diffStats.getWriteTicks()) / numOfIOs : 0;
// svctm
double svcTime = numOfIOs > 0 ? diffStats.getNumberOfIOInMs() / numOfIOs : 0;
// %util
double busy = 0;
if (deltaMS > 0) {
busy = 100 * diffStats.getNumberOfIOInMs() / deltaMS;
busy = busy > 100 ? 100 : busy;
}
diskStatsList.add(new DiskStats(diskId, Double.parseDouble(decimalFormat.format(getRate(diffStats.getNumberOfReads(), deltaMS))), Double.parseDouble(decimalFormat.format(getRate(diffStats.getSectorsRead(), deltaMS))), Double.parseDouble(decimalFormat.format(getRate(diffStats.getNumberOfWrites(), deltaMS))), Double.parseDouble(decimalFormat.format(getRate(diffStats.getSectorsWrite(), deltaMS))), Double.parseDouble(decimalFormat.format(wait)), Double.parseDouble(decimalFormat.format(svcTime)), Double.parseDouble(decimalFormat.format(busy))));
}
return diskStatsList;
}
use of com.emc.vipr.model.sys.healthmonitor.DiskStats in project coprhd-controller by CoprHD.
the class HealthMonitorServiceTest method verifyNodeStats.
private void verifyNodeStats(NodeStats nodeStats) {
Assert.assertTrue(nodeStats.getDiskStatsList() != null && !nodeStats.getDiskStatsList().isEmpty());
Assert.assertTrue(nodeStats.getServiceStatsList() != null && !nodeStats.getServiceStatsList().isEmpty());
// service stats
for (ServiceStats serviceStats : nodeStats.getServiceStatsList()) {
Assert.assertTrue(serviceStats.getServiceName() != null && !serviceStats.getServiceName().isEmpty());
Assert.assertNotNull(serviceStats.getCommand());
Assert.assertTrue(serviceStats.getFileDescriptors() >= 0);
Assert.assertNotNull(serviceStats.getProcessStatus());
Assert.assertNotNull(serviceStats.getProcessStatus().getStartTime());
Assert.assertNotNull(serviceStats.getProcessStatus().getUpTime());
Assert.assertTrue(serviceStats.getProcessStatus().getNumberOfThreads() >= 0);
Assert.assertTrue(serviceStats.getProcessStatus().getResidentMem() >= 0);
Assert.assertTrue(serviceStats.getProcessStatus().getVirtualMemSizeInBytes() >= 0);
}
// Node stats
Assert.assertEquals(NODE_ID, nodeStats.getNodeId());
Assert.assertEquals(NODE_NAME, nodeStats.getNodeName());
Assert.assertEquals(NODE_IP, nodeStats.getIp());
Assert.assertNotNull(nodeStats.getMemoryStats());
Assert.assertNotNull(nodeStats.getMemoryStats().getMemFree());
Assert.assertNotNull(nodeStats.getMemoryStats().getMemBuffers());
Assert.assertNotNull(nodeStats.getMemoryStats().getMemTotal());
Assert.assertNotNull(nodeStats.getLoadAvgStats());
Assert.assertTrue(nodeStats.getLoadAvgStats().getLoadAvgTasksPastFifteenMinutes() >= 0);
Assert.assertTrue(nodeStats.getLoadAvgStats().getLoadAvgTasksPastFiveMinutes() >= 0);
Assert.assertTrue(nodeStats.getLoadAvgStats().getLoadAvgTasksPastMinute() >= 0);
// disk stats
for (DiskStats diskStats : nodeStats.getDiskStatsList()) {
Assert.assertNotNull(diskStats.getDiskId());
Assert.assertTrue(diskStats.getSectorsReadPerSec() >= 0);
Assert.assertTrue(diskStats.getSectorsWritePerSec() >= 0);
Assert.assertTrue(diskStats.getReadPerSec() >= 0);
Assert.assertTrue(diskStats.getWritePerSec() >= 0);
Assert.assertTrue(diskStats.getUtilPerc() >= 0);
Assert.assertTrue(diskStats.getAvgSvcTime() >= 0);
Assert.assertTrue(diskStats.getAvgWait() >= 0);
}
// Test service list order
Assert.assertEquals(AVAILABLE_SERVICES.get(0), nodeStats.getServiceStatsList().get(0).getServiceName());
}
use of com.emc.vipr.model.sys.healthmonitor.DiskStats in project coprhd-controller by CoprHD.
the class HealthMonitorServiceTest method testNodeStatsWithNoAvailableServices.
@Test
public void testNodeStatsWithNoAvailableServices() {
NodeStats nodeStats = getNodeStats(NODE_ID, NODE_NAME, NODE_IP, 0, null);
Assert.assertTrue(nodeStats.getDiskStatsList() != null && !nodeStats.getDiskStatsList().isEmpty());
Assert.assertTrue(nodeStats.getServiceStatsList() != null && !nodeStats.getServiceStatsList().isEmpty());
// service stats
for (ServiceStats serviceStats : nodeStats.getServiceStatsList()) {
Assert.assertTrue(serviceStats.getServiceName() != null && !serviceStats.getServiceName().isEmpty());
}
// Node stats
Assert.assertEquals(NODE_ID, nodeStats.getNodeId());
Assert.assertEquals(NODE_NAME, nodeStats.getNodeName());
Assert.assertEquals(NODE_IP, nodeStats.getIp());
Assert.assertNotNull(nodeStats.getMemoryStats().getMemFree());
// disk stats
for (DiskStats diskStats : nodeStats.getDiskStatsList()) {
Assert.assertNotNull(diskStats.getDiskId());
}
}
Aggregations