1 19 20 package com.sslexplorer.setup.forms; 21 22 import java.net.InetAddress ; 23 import java.net.NetworkInterface ; 24 import java.net.SocketException ; 25 import java.util.ArrayList ; 26 import java.util.Enumeration ; 27 import java.util.List ; 28 29 import org.apache.commons.logging.Log; 30 import org.apache.commons.logging.LogFactory; 31 32 import com.sslexplorer.boot.ContextHolder; 33 import com.sslexplorer.core.forms.CoreForm; 34 import com.sslexplorer.setup.SystemInformationRegistry; 35 36 37 43 public class SystemInfoForm extends CoreForm { 44 45 static Log log = LogFactory.getLog(SystemInfoForm.class); 46 47 48 49 55 public String getTotalMemoryK() { 56 return String.valueOf(Runtime.getRuntime().totalMemory() / 1024); 57 } 58 59 65 public String getFreeMemoryK() { 66 return String.valueOf(Runtime.getRuntime().freeMemory() / 1024); 67 } 68 69 70 76 public String getUsedMemoryK() { 77 return String.valueOf((Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()) / 1024); 78 } 79 80 85 public String getOSArch() { 86 return System.getProperty("os.arch"); 87 } 88 89 94 public String getOSName() { 95 return System.getProperty("os.name"); 96 } 97 98 103 public String getOSVersion() { 104 return System.getProperty("os.version"); 105 } 106 107 108 113 public String getJavaVersion() { 114 return System.getProperty("java.version"); 115 } 116 117 122 public String getServerPort() { 123 return String.valueOf(ContextHolder.getContext().getPort()); 124 } 125 126 131 public String getActiveThreads() { 132 try { 133 return String.valueOf(Thread.activeCount()); 134 } catch (RuntimeException e) { 135 return "unknown"; 136 } 137 } 138 139 144 public String getCPUCount() { 145 return String.valueOf(Runtime.getRuntime().availableProcessors()); 146 } 147 148 156 public List getNetworkInterfaces() { 157 Enumeration e = null; 158 try { 159 List niList = new ArrayList (); 160 e = NetworkInterface.getNetworkInterfaces(); 161 while (e.hasMoreElements()) { 162 NetworkInterface netface = (NetworkInterface ) e.nextElement(); 163 Enumeration e2 = netface.getInetAddresses(); 164 while (e2.hasMoreElements()) { 165 InetAddress ip = (InetAddress ) e2.nextElement(); 166 niList.add(netface.getName() + "=" + ip.toString()); 167 } 168 } 169 return niList; 170 } catch (SocketException e1) { 171 return new ArrayList (); 172 } 173 } 174 175 180 public String getThreadDump() { 181 StringBuffer buf = new StringBuffer (); 182 Thread thread = ContextHolder.getContext().getMainThread(); 183 if (thread != null) { 184 ThreadGroup group = thread.getThreadGroup(); 185 try { 186 if (group != null) { 187 dumpThread(group, 0, buf); 188 } else { 189 buf.append("[No main thread group]"); 190 } 191 } catch (Throwable t) { 192 log.error("Failed to get thread dump.", t); 193 } 194 } else { 195 buf.append("[No main thread]"); 196 } 197 return buf.toString(); 198 } 199 200 private void dumpThread(ThreadGroup group, int level, StringBuffer buf) { 201 for (int i = 0; i < level; i++) { 202 buf.append(" "); 203 } 204 buf.append("["); 205 buf.append(group.getName()); 206 buf.append("]"); 207 Thread [] t = new Thread [group.activeCount()]; 208 group.enumerate(t); 209 for (int i = 0; t != null && i < t.length; i++) { 210 if (t[i].getThreadGroup() == group) { 211 buf.append("\n"); 212 for (int j = 0; j < level + 1; j++) { 213 buf.append(" "); 214 } 215 buf.append(t[i].getName()); 216 buf.append(" (pri. "); 217 buf.append(t[i].getPriority()); 218 buf.append(")"); 219 } 220 } 221 ThreadGroup [] g = new ThreadGroup [group.activeGroupCount()]; 222 group.enumerate(g); 223 for (int i = 0; g != null && i < g.length; i++) { 224 buf.append("\n"); 225 dumpThread(g[i], level + 1, buf); 226 } 227 } 228 229 230 public List getSystemInformationProviders() { 231 return SystemInformationRegistry.getInstance().getProviders(); 232 } 233 } | Popular Tags |