use of com.emc.vipr.model.sys.healthmonitor.ServiceStats in project coprhd-controller by CoprHD.
the class NodeStatsExtractor method getServiceStats.
/**
* Method that returns all service statistics in the order of availableservices list.
*/
public static List<ServiceStats> getServiceStats(List<String> availableServices) {
List<ServiceStats> serviceStatsList = new ArrayList<ServiceStats>();
Map<String, ServiceStats> tempServiceStatsMap = new HashMap<String, ServiceStats>();
File procDir = new File(PROC_DIR);
File[] procFiles = procDir.listFiles();
// /proc/[pid]/(comm,cmdline,stat,statm,fd) files.
for (File procFile : procFiles) {
String pid = procFile.getName().trim();
if (pid.equalsIgnoreCase(SELF_DIR)) {
continue;
}
try {
String serviceName = ProcStats.getServiceName(pid);
if (!serviceName.isEmpty() && !MONITOR_SVCNAME.equals(serviceName)) {
String commandFile = null;
try {
commandFile = FileReadUtil.readFirstLine(String.format(COMM_FILE, pid));
} catch (Exception e) {
_log.error("Error occurred while reading command file: {}", e);
}
_log.info("Get serviceStats for service {}", serviceName);
if (serviceName.contains(COVERAGE_SVCNAME_SUFFIX)) {
serviceName = serviceName.split("-")[0];
}
ServiceStats serviceStats = new ServiceStats(serviceName, commandFile, ProcStats.getFileDescriptorCntrs(pid), ProcStats.getProcStats(pid));
tempServiceStatsMap.put(serviceName, serviceStats);
}
} catch (SyssvcException ex) {
if (ex.getServiceCode() == ServiceCode.SYS_INTERNAL_SERVICE_NAME_NOT_FOUND) {
continue;
}
_log.debug("Syssvc Exception: {}", ex);
} catch (Exception e) {
_log.debug("Internal error: {}", e);
}
}
// Ordering service stats
if (availableServices == null || availableServices.isEmpty()) {
_log.warn("List of available services is null or empty: {}", availableServices);
return new ArrayList<ServiceStats>(tempServiceStatsMap.values());
} else {
for (String svcName : availableServices) {
if (tempServiceStatsMap.containsKey(svcName)) {
serviceStatsList.add(tempServiceStatsMap.remove(svcName));
} else {
serviceStatsList.add(new ServiceStats(svcName));
}
}
return serviceStatsList;
}
}
use of com.emc.vipr.model.sys.healthmonitor.ServiceStats 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.ServiceStats 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());
}
}
use of com.emc.vipr.model.sys.healthmonitor.ServiceStats in project coprhd-controller by CoprHD.
the class SystemHealth method listServicesJson.
public static void listServicesJson(String nodeId) {
List<ServiceStats> serviceStatsList = MonitorUtils.getNodeStats(nodeId).getServiceStatsList();
List<ServiceHealth> serviceHealthList = MonitorUtils.getNodeHealth(nodeId).getServiceHealthList();
List<NodeServicesDataTable.Services> servicesList = Lists.newArrayList();
for (ServiceStats service : serviceStatsList) {
for (ServiceHealth health : serviceHealthList) {
if (service.getServiceName().equals(health.getServiceName())) {
servicesList.add(new NodeServicesDataTable.Services(nodeId, health, service));
}
}
}
renderJSON(DataTablesSupport.createSource(servicesList, params));
}
Aggregations