1 23 package com.sun.enterprise.diagnostics.collect; 24 25 import com.sun.logging.LogDomains; 26 import com.sun.enterprise.diagnostics.Data; 27 import com.sun.enterprise.diagnostics.Defaults; 28 29 import java.io.*; 30 import java.util.logging.Level ; 31 import java.util.logging.Logger ; 32 33 34 37 public class SolarisSystemInfoCollector implements Collector { 38 39 40 private static Logger logger = 41 LogDomains.getLogger(LogDomains.ADMIN_LOGGER); 42 43 44 private static final String HARD_DISK_INFO_CMD = "df -k | grep /dev | grep " + 45 "-v /dev/fd | awk '{print $1, $2, $6}'"; 46 private static final String MEMORY_INFO_CMD = "/usr/sbin/prtconf | grep" + 47 " 'Memory size'"; 48 private static final String NETWORK_SETTINGS_CMD = "ifconfig -a | egrep" + 49 " '^hme|^qfe' | awk '{print $1, $2, $6}'"; 50 private static final String TCP_SETTINGS_CMD = "ndd /dev/tcp " + 51 "tcp_time_wait_interval"; 52 private static final String IP_ADDRESS_INFO_CMD = "netstat -in |" + 53 " /usr/xpg4/bin/grep -Ev 'Name|lo0' | awk '{print $4}'"; 54 private static final String OS_LEVEL_PATCH_INFO_CMD = "showrev -p"; 55 private static final String HOST_NAME_CMD = "hostname"; 56 private static final String DOMAIN_NAME_CMD = "domainname"; 57 private static final String SOFT_FILE_DESC_LIMIT_CMD = "ulimit -n"; 58 private static final String HARD_FILE_DESC_LIMIT_CMD = "ulimit -Hn"; 59 private static final String PROCESSOR_INFO_CMD = "psrinfo -v | grep " + 60 "'processor operates at'"; 61 private static final String SWAP_INFO_CMD = "swap -s"; 62 private String destFolder = null; 63 64 65 public SolarisSystemInfoCollector(String destFolder){ 66 this.destFolder = destFolder; 67 } 68 69 74 public Data capture(){ 75 76 FileData data = null; 77 78 String outputFileName = destFolder + File.separator + Defaults.SYSTEM_INFO_FILE; 79 80 final String ALL_CMDS = 81 "( " + 82 " echo 'HOST NAME' ; "+ HOST_NAME_CMD + 83 " ; echo 'DOMAIN NAME' ; "+DOMAIN_NAME_CMD + 84 " ; echo 'HARD DISK INFO ' ; "+HARD_DISK_INFO_CMD + 85 " ; echo 'NETWORK CONFIGURATION ' ; "+NETWORK_SETTINGS_CMD + 86 " ; echo 'IP ADDRESS ' ; "+ IP_ADDRESS_INFO_CMD + 87 " ; echo 'OS LEVEL PATCH INFO' ; "+OS_LEVEL_PATCH_INFO_CMD + 88 " ; echo 'SOFT FILE DESCRIPTOR LIMIT ' ; "+SOFT_FILE_DESC_LIMIT_CMD + 89 " ; echo 'HARD FILE DESCRIPTOR LIMIT ' ; "+HARD_FILE_DESC_LIMIT_CMD + 90 " ; echo 'PROCESSOR INFO' ; "+PROCESSOR_INFO_CMD + 91 " ; echo 'SWAP SPACE' ; "+SWAP_INFO_CMD + 92 " ; echo 'MEMORY INFO ' ; " + MEMORY_INFO_CMD + 93 " ) >> "+ outputFileName ; 94 95 String [] cmd = {"sh", "-c", ALL_CMDS}; 96 97 ProcessExecutor executor = new ProcessExecutor(cmd, 0); 98 try{ 99 executor.execute(); 100 101 File outputFile = new File(outputFileName); 102 103 data = new FileData(outputFile.getName(),DataType.SYSTEM_INFO); 104 } 105 catch(ProcessExecutorException pee){ 106 logger.log(Level.WARNING, "Exception while capturing system info" + 107 " : " + pee.getMessage()); 108 } 109 return data; 110 } 111 } 112 | Popular Tags |