Search in sources :

Example 1 with ServiceStats

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;
    }
}
Also used : ServiceStats(com.emc.vipr.model.sys.healthmonitor.ServiceStats) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) SyssvcException(com.emc.storageos.systemservices.exceptions.SyssvcException) File(java.io.File) SyssvcException(com.emc.storageos.systemservices.exceptions.SyssvcException)

Example 2 with ServiceStats

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());
}
Also used : DiskStats(com.emc.vipr.model.sys.healthmonitor.DiskStats) ServiceStats(com.emc.vipr.model.sys.healthmonitor.ServiceStats)

Example 3 with ServiceStats

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());
    }
}
Also used : NodeStats(com.emc.vipr.model.sys.healthmonitor.NodeStats) DiskStats(com.emc.vipr.model.sys.healthmonitor.DiskStats) ServiceStats(com.emc.vipr.model.sys.healthmonitor.ServiceStats) Test(org.junit.Test)

Example 4 with ServiceStats

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));
}
Also used : ServiceStats(com.emc.vipr.model.sys.healthmonitor.ServiceStats) NodeServicesDataTable(models.datatable.NodeServicesDataTable) ServiceHealth(com.emc.vipr.model.sys.healthmonitor.ServiceHealth)

Aggregations

ServiceStats (com.emc.vipr.model.sys.healthmonitor.ServiceStats)4 DiskStats (com.emc.vipr.model.sys.healthmonitor.DiskStats)2 SyssvcException (com.emc.storageos.systemservices.exceptions.SyssvcException)1 NodeStats (com.emc.vipr.model.sys.healthmonitor.NodeStats)1 ServiceHealth (com.emc.vipr.model.sys.healthmonitor.ServiceHealth)1 File (java.io.File)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 NodeServicesDataTable (models.datatable.NodeServicesDataTable)1 Test (org.junit.Test)1