1 34 package net.myvietnam.mvncore.info; 35 36 public class SystemInfo { 37 38 private String vmName; 39 private String vmVendor; 40 private String vmVersion; 41 private String runtimeName; 42 private String runtimeVersion; 43 private String osName; 44 private String osVersion; 45 private String cpu; 46 47 long totalMemory = 0; 48 long freeMemory = 0; 49 long totalMemoryKB = 0; 50 long freeMemoryKB = 0; 51 52 public SystemInfo() { 53 vmName = getProperty("java.vm.name"); 54 vmVendor = getProperty("java.vm.vendor"); 55 vmVersion = getProperty("java.vm.version"); 56 runtimeName = getProperty("java.runtime.name"); 57 runtimeVersion = getProperty("java.runtime.version"); 58 osName = getProperty("os.name"); 59 osVersion = getProperty("os.version"); 60 cpu = getProperty("sun.cpu.isalist"); 61 62 Runtime runtime = Runtime.getRuntime(); 63 totalMemory = runtime.totalMemory(); 64 freeMemory = runtime.freeMemory(); 65 totalMemoryKB = totalMemory/1024; 66 freeMemoryKB = freeMemory/1024; 67 } 68 69 public static String getProperty(String key) { 70 String retValue = null; 71 try { 72 retValue = System.getProperty(key, ""); 73 } catch (Exception ex) { 74 retValue = "no access"; 75 } 76 return retValue; 77 } 78 79 public String getCpu() { 80 return cpu; 81 } 82 83 public String getOsName() { 84 return osName; 85 } 86 87 public String getOsVersion() { 88 return osVersion; 89 } 90 91 public String getRuntimeName() { 92 return runtimeName; 93 } 94 95 public String getRuntimeVersion() { 96 return runtimeVersion; 97 } 98 99 public String getVmName() { 100 return vmName; 101 } 102 103 public String getVmVendor() { 104 return vmVendor; 105 } 106 107 public String getVmVersion() { 108 return vmVersion; 109 } 110 111 public long getFreeMemory() { 112 return freeMemory; 113 } 114 115 public long getFreeMemoryKB() { 116 return freeMemoryKB; 117 } 118 119 public long getTotalMemory() { 120 return totalMemory; 121 } 122 123 public long getTotalMemoryKB() { 124 return totalMemoryKB; 125 } 126 } 127 | Popular Tags |