This script will do that
var df = new java.text.SimpleDateFormat("dd/MM/yy HH:mm:ss.SSS");
var calobj = java.util.Calendar.getInstance();
tw.local.SystemInfo[tw.local.SystemInfo.listLength] = new tw.object.toolkit.TWSYS.NameValuePair();
tw.local.SystemInfo[tw.local.SystemInfo.listLength-1].name = "System Date Time";
tw.local.SystemInfo[tw.local.SystemInfo.listLength-1].value ="" + df.format(calobj.getTime());
var cpucnt = java.lang.Runtime.getRuntime().availableProcessors();
tw.local.SystemInfo[tw.local.SystemInfo.listLength] = new tw.object.toolkit.TWSYS.NameValuePair();
tw.local.SystemInfo[tw.local.SystemInfo.listLength-1].name = "CPU Count";
tw.local.SystemInfo[tw.local.SystemInfo.listLength-1].value ="" + cpucnt;
function formatBytes(bytes,decimals) {
if(bytes == 0) return '0 Bytes';
var k = 1024,
dm = decimals || 2,
sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'],
i = Math.floor(Math.log(bytes) / Math.log(k));
return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + ' ' + sizes[i];
}
var inetAddress = java.net.InetAddress.getLocalHost();
var intet6Address = java.net.Inet6Address.getLocalHost();
var ipByte = intet6Address.getAllByName(inetAddress.getHostName());
var ip = "";
for( var cnt=0; cnt < ipByte.length; cnt++ ) {
try{
ip += (ipByte[cnt] < 0 ? ipByte[cnt]+256 : ipByte[cnt])+".";
} catch (e){
;
}
}
var host = inetAddress.getHostName();
var add = [];
add = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 ];
//getByAddress() method
var ip1 = java.net.Inet6Address.getByAddress(host, add, 5);
var ip2 = java.net.Inet6Address.getByAddress(null, add, 6);
var ipv6addr = ip1.getAddress().join("");
ipv6addr += ", " + ip2.getAddress().join("");
tw.local.SystemInfo[tw.local.SystemInfo.listLength] = new tw.object.toolkit.TWSYS.NameValuePair();
tw.local.SystemInfo[tw.local.SystemInfo.listLength-1].name = "Host Name";
tw.local.SystemInfo[tw.local.SystemInfo.listLength-1].value ="" + inetAddress.getHostName();
tw.local.SystemInfo[tw.local.SystemInfo.listLength] = new tw.object.toolkit.TWSYS.NameValuePair();
tw.local.SystemInfo[tw.local.SystemInfo.listLength-1].name = "IPV4 Adddress";
tw.local.SystemInfo[tw.local.SystemInfo.listLength-1].value ="" + inetAddress.getHostAddress();
tw.local.SystemInfo[tw.local.SystemInfo.listLength] = new tw.object.toolkit.TWSYS.NameValuePair();
tw.local.SystemInfo[tw.local.SystemInfo.listLength-1].name = "IPV6 Adddress";
tw.local.SystemInfo[tw.local.SystemInfo.listLength-1].value ="" + ipv6addr;
var rt = java.lang.Runtime.getRuntime();
var total_mem = formatBytes(rt.totalMemory(),2);
var free_mem = formatBytes(rt.freeMemory(),2);
var used_mem = formatBytes(rt.totalMemory() - rt.freeMemory(), 2);
tw.local.SystemInfo[tw.local.SystemInfo.listLength] = new tw.object.toolkit.TWSYS.NameValuePair();
tw.local.SystemInfo[tw.local.SystemInfo.listLength-1].name = "Total Memory";
tw.local.SystemInfo[tw.local.SystemInfo.listLength-1].value ="" + total_mem;
tw.local.SystemInfo[tw.local.SystemInfo.listLength] = new tw.object.toolkit.TWSYS.NameValuePair();
tw.local.SystemInfo[tw.local.SystemInfo.listLength-1].name = "Free Memory";
tw.local.SystemInfo[tw.local.SystemInfo.listLength-1].value = "" + free_mem;
tw.local.SystemInfo[tw.local.SystemInfo.listLength] = new tw.object.toolkit.TWSYS.NameValuePair();
tw.local.SystemInfo[tw.local.SystemInfo.listLength-1].name = "Used Memory";
tw.local.SystemInfo[tw.local.SystemInfo.listLength-1].value = "" + used_mem;
var mbs = java.lang.management.ManagementFactory.getPlatformMBeanServer();
var name = javax.management.ObjectName.getInstance("java.lang:type=OperatingSystem");
var str1 = new java.lang.String( "ProcessCpuLoad" );
var arr1 = [];
arr1[0] = str1;
var list = mbs.getAttributes(name, arr1);
if (list.isEmpty()) cpu = 0;
var att = list.get(0);
var value = att.getValue();
// usually takes a couple of seconds before we get real values
if (value == -1.0) cpu =0;
// returns a percentage value with 1 decimal point precision
cpu = (value * 1000) / 10.0;
tw.local.SystemInfo[tw.local.SystemInfo.listLength] = new tw.object.toolkit.TWSYS.NameValuePair();
tw.local.SystemInfo[tw.local.SystemInfo.listLength-1].name = "" + "CPU Load" ;
tw.local.SystemInfo[tw.local.SystemInfo.listLength-1].value = "" + cpu;
var file = new java.io.File("/");
var usableSpace = file.getUsableSpace(); ///unallocated / free disk space in bytes.
var freeSpace = file.getFreeSpace(); //unallocated / free disk space in bytes.
var totalspace = file.getTotalSpace();
var usedSpace = totalspace - freeSpace;
tw.local.SystemInfo[tw.local.SystemInfo.listLength] = new tw.object.toolkit.TWSYS.NameValuePair();
tw.local.SystemInfo[tw.local.SystemInfo.listLength-1].name = "" + "Total Space" ;
tw.local.SystemInfo[tw.local.SystemInfo.listLength-1].value = "" + formatBytes(totalspace, 2);
tw.local.SystemInfo[tw.local.SystemInfo.listLength] = new tw.object.toolkit.TWSYS.NameValuePair();
tw.local.SystemInfo[tw.local.SystemInfo.listLength-1].name = "" + "Used Space" ;
tw.local.SystemInfo[tw.local.SystemInfo.listLength-1].value = "" + formatBytes(usedSpace, 2);
tw.local.SystemInfo[tw.local.SystemInfo.listLength] = new tw.object.toolkit.TWSYS.NameValuePair();
tw.local.SystemInfo[tw.local.SystemInfo.listLength-1].name = "" + "Free Space" ;
tw.local.SystemInfo[tw.local.SystemInfo.listLength-1].value = "" + formatBytes(freeSpace,2);
try{
var runtimeMXBean = java.lang.management.ManagementFactory.getRuntimeMXBean();
var methods1 = runtimeMXBean.getClass().getDeclaredMethods();
for (var i=0; i < methods1.length; i++) {
methods1[i].setAccessible(true);
if (java.lang.reflect.Modifier.isPublic(methods1[i].getModifiers())) {
var value1;
value1 = methods1[i].invoke(runtimeMXBean);
tw.local.SystemInfo[tw.local.SystemInfo.listLength] = new tw.object.toolkit.TWSYS.NameValuePair();
tw.local.SystemInfo[tw.local.SystemInfo.listLength-1].name = "" + methods1[i].getName() ;
tw.local.SystemInfo[tw.local.SystemInfo.listLength-1].value = "" + value1;
} // if
} // for
} catch(e){
}
tw.local.SystemInfo[tw.local.SystemInfo.listLength] = new tw.object.toolkit.TWSYS.NameValuePair();
tw.local.SystemInfo[tw.local.SystemInfo.listLength-1].name = "JVM Runtime Arguments" ;
var rta = runtimeMXBean.getInputArguments();
var rtastr = "";
for (var cnt1 =0; cnt1 < rta.size(); cnt1++){
rtastr += ""+ rta.get(cnt1) + " ";
}
tw.local.SystemInfo[tw.local.SystemInfo.listLength-1].value ="" + rtastr;
;
function dhm(t){
var cd = 24 * 60 * 60 * 1000,
ch = 60 * 60 * 1000,
d = Math.floor(t / cd),
h = Math.floor( (t - d * cd) / ch),
m = Math.round( (t - d * cd - h * ch) / 60000),
pad = function(n){ return n < 10 ? '0' + n : n; };
if( m === 60 ){
h++;
m = 0;
}
if( h === 24 ){
d++;
h = 0;
}
return [d+" Days ", pad(h)+" Hours ", pad(m)+" Minutes "].join(':');
}
tw.local.SystemInfo[tw.local.SystemInfo.listLength] = new tw.object.toolkit.TWSYS.NameValuePair();
tw.local.SystemInfo[tw.local.SystemInfo.listLength-1].name = "JVM Uptime " ;
tw.local.SystemInfo[tw.local.SystemInfo.listLength-1].value = "" + dhm(runtimeMXBean.getUptime());
try{
var operatingSystemMXBean = java.lang.management.ManagementFactory.getOperatingSystemMXBean();
var methods = operatingSystemMXBean.getClass().getDeclaredMethods();
for (var i=0; i < methods.length; i++) {
methods[i].setAccessible(true);
if (java.lang.reflect.Modifier.isPublic(methods[i].getModifiers())) {
var value;
value = methods[i].invoke(operatingSystemMXBean);
tw.local.SystemInfo[tw.local.SystemInfo.listLength] = new tw.object.toolkit.TWSYS.NameValuePair();
tw.local.SystemInfo[tw.local.SystemInfo.listLength-1].name = "" + methods[i].getName() ;
tw.local.SystemInfo[tw.local.SystemInfo.listLength-1].value = "" + value;
} // if
} // for
} catch(e){
}
var p = java.lang.System.getProperties();
var keys = p.keys();
while (keys.hasMoreElements()) {
tw.local.SystemInfo[tw.local.SystemInfo.listLength] = new tw.object.toolkit.TWSYS.NameValuePair();
var key = ""+keys.nextElement();
var value = "" + p.get(key);
tw.local.SystemInfo[tw.local.SystemInfo.listLength-1].name = key;
tw.local.SystemInfo[tw.local.SystemInfo.listLength-1].value = value;
}
tw.local.results = tw.local.SystemInfo;