use of com.emc.storageos.systemservices.exceptions.SyssvcException 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;
}
}
Aggregations