Getting system hardware and software info from Java¶
Sometimes there is a need to include in bug report information about
user hardware/software, in Java it can be done using library
SIGAR (System Information Gatherer And Reporter)
or using informations provided by Runtime
class and System.getProperty()
method.
Below is presented simple application (extreme simple - using only System.out.println())
created only
to demonstrate which values can be pulled out from JRE.
Source code¶
package systeminfo;
import java.io.File;
public class Main {
public static void main(String[] args) {
String sep = "##########################################################################";
System.out.println(sep);
System.out.println("#### " + "Hardware information");
System.out.println(sep);
System.out.println("Available processors: " + Runtime.getRuntime().availableProcessors() + " cores");
System.out.println("Free memory: " + Runtime.getRuntime().freeMemory() + " bytes");
long maxMemory = Runtime.getRuntime().maxMemory();
System.out.println("Maximum memory: " +
(maxMemory == Long.MAX_VALUE ? "no limit" : maxMemory) + " bytes");
System.out.println("Total memory : " + Runtime.getRuntime().totalMemory() + " bytes");
/* Get a list of all filesystem roots on this system */
File[] roots = File.listRoots();
/* For each filesystem root, print some info */
for (File root : roots) {
System.out.println("File system root: " + root.getAbsolutePath());
System.out.println("\tTotal space: " + root.getTotalSpace() + " bytes");
System.out.println("\tFree space: " + root.getFreeSpace() + " bytes");
System.out.println("\tUsable space: " + root.getUsableSpace() + " bytes");
}
System.out.println(sep);
System.out.println("");
System.out.println("");
System.out.println(sep);
System.out.println("#### " + "Software information");
System.out.println(sep);
System.out.println("");
System.out.println(sep);
System.out.println("## " + "Java Virtual Machine (JVM) information");
System.out.println("JVM specification version: " + System.getProperty("java.vm.specification.version"));
System.out.println("JVM specification vendor: " + System.getProperty("java.vm.specification.vendor"));
System.out.println("JVM specification name: " + System.getProperty("java.vm.specification.name"));
System.out.println("JVM implementation version: " + System.getProperty("java.vm.version"));
System.out.println("JVM implementation vendor: " + System.getProperty("java.vm.vendor"));
System.out.println("JVM implementation name: " + System.getProperty("java.vm.name"));
System.out.println("");
System.out.println(sep);
System.out.println("## " + "Java Runtime Enviroment (JRE) informations");
System.out.println("JRE version: " + System.getProperty("java.version"));
System.out.println("JRE vendor name: " + System.getProperty("java.vendor"));
System.out.println("JRE vendor url: " + System.getProperty("java.vendor.url"));
System.out.println("JRE specification version: " + System.getProperty("java.specification.version"));
System.out.println("JRE specification vendor: " + System.getProperty("java.specification.vendor"));
System.out.println("JRE specification name: " + System.getProperty("java.specification.name"));
System.out.println("JRE installation direcotry: " + System.getProperty("java.home"));
System.out.println("");
System.out.println(sep);
System.out.println("## " + "Java internals / misc");
System.out.println("Java class format version number: " + System.getProperty("java.class.version"));
System.out.println("Path of java class: " + System.getProperty("java.class.path"));
System.out.println("List of paths to search when loading libraries: " + System.getProperty("java.library.path"));
System.out.println("The path of temp file: " + System.getProperty("java.io.tmpdir"));
System.out.println("The Name of JIT compiler to use: " + System.getProperty("java.compiler"));
System.out.println("The path of extension directory or directories: " + System.getProperty("java.ext.dirs"));
System.out.println("");
System.out.println(sep);
System.out.println("## " + "OS specific information");
System.out.println("The name of OS name: " + System.getProperty("os.name"));
System.out.println("The OS architecture: " + System.getProperty("os.arch"));
System.out.println("The version of OS: " + System.getProperty("os.version"));
System.out.println("The File separator: " + System.getProperty("file.separator"));
System.out.println("The path separator: " + System.getProperty("path.separator"));
System.out.println("The line separator: " + System.getProperty("line.separator"));
System.out.println("");
System.out.println(sep);
System.out.println("## " + "OS user information");
System.out.println("The Locale is: " + System.getProperty("user.language"));
System.out.println("The name of account name user: " + System.getProperty("user.name"));
System.out.println("The home directory of user: " + System.getProperty("user.home"));
System.out.println("The current working directory of the user: " + System.getProperty("user.dir"));
System.out.println(sep);
System.out.println(sep);
} // main
}
Sample output¶
##########################################################################
#### Hardware information
##########################################################################
Available processors: 2 cores
Free memory: 32734640 bytes
Maximum memory: 506920960 bytes
Total memory : 32964608 bytes
File system root: /
Total space: 64964423680 bytes
Free space: 38344318976 bytes
Usable space: 38344318976 bytes
##########################################################################
##########################################################################
#### Software information
##########################################################################
##########################################################################
## Java Virtual Machine (JVM) information
JVM specification version: 1.0
JVM specification vendor: Sun Microsystems Inc.
JVM specification name: Java Virtual Machine Specification
JVM implementation version: 14.2-b01
JVM implementation vendor: Sun Microsystems Inc.
JVM implementation name: Java HotSpot(TM) Server VM
##########################################################################
## Java Runtime Enviroment (JRE) informations
JRE version: 1.6.0_16
JRE vendor name: Sun Microsystems Inc.
JRE vendor url: http://java.sun.com/
JRE specification version: 1.6
JRE specification vendor: Sun Microsystems Inc.
JRE specification name: Java Platform API Specification
JRE installation direcotry: /usr/lib/jvm/java-6-sun-1.6.0.16/jre
##########################################################################
## Java internals / misc
Java class format version number: 50.0
Path of java class: /home/johny/NetBeansProjects/SystemInfo/build/classes:/home/johny/NetBeansProjects/SystemInfo/src
List of paths to search when loading libraries: /usr/lib/jvm/java-6-sun-1.6.0.16/jre/lib/i386/server:/usr/lib/jvm/java-6-sun-1.6.0.16/jre/lib/i386:/usr/lib/jvm/java-6-sun-1.6.0.16/jre/../lib/i386:/usr/lib/jvm/java-6-sun-1.6.0.16/jre/lib/i386/client:/usr/lib/jvm/java-6-sun-1.6.0.16/jre/lib/i386:/usr/lib/jvm/java-6-sun-1.6.0.16/jre/../lib/i386:/usr/java/packages/lib/i386:/lib:/usr/lib
The path of temp file: /tmp
The Name of JIT compiler to use: null
The path of extension directory or directories: /usr/lib/jvm/java-6-sun-1.6.0.16/jre/lib/ext:/usr/java/packages/lib/ext
##########################################################################
## OS specific information
The name of OS name: Linux
The OS architecture: i386
The version of OS: 2.6.28-15-generic
The File separator: /
The path separator: :
The line separator:
##########################################################################
## OS user information
The Locale is: pl
The name of account name user: johny
The home directory of user: /home/johny
The current working directory of the user: /home/johny/NetBeansProjects/SystemInfo
##########################################################################
##########################################################################