From 5e7dbfd40e771dd2ed922cc78efbfe932400cb17 Mon Sep 17 00:00:00 2001 From: John Sachs Date: Fri, 12 Nov 2004 04:05:47 +0000 Subject: [PATCH] add sysinfo command --- .../java/src/net/hyperic/sigar/cmd/Shell.java | 1 + .../src/net/hyperic/sigar/cmd/SysInfo.java | 119 ++++++++++++++++++ 2 files changed, 120 insertions(+) create mode 100644 bindings/java/src/net/hyperic/sigar/cmd/SysInfo.java diff --git a/bindings/java/src/net/hyperic/sigar/cmd/Shell.java b/bindings/java/src/net/hyperic/sigar/cmd/Shell.java index 765e0c5c..de94a840 100644 --- a/bindings/java/src/net/hyperic/sigar/cmd/Shell.java +++ b/bindings/java/src/net/hyperic/sigar/cmd/Shell.java @@ -67,6 +67,7 @@ public class Shell extends ShellBase { registerCommandHandler("netstat", new Netstat(this)); registerCommandHandler("version", new Version(this)); registerCommandHandler("mps", new MultiPs(this)); + registerCommandHandler("sysinfo", new SysInfo(this)); try { //requires junit.jar registerCommandHandler("test", new SigarTestRunner(this)); diff --git a/bindings/java/src/net/hyperic/sigar/cmd/SysInfo.java b/bindings/java/src/net/hyperic/sigar/cmd/SysInfo.java new file mode 100644 index 00000000..b5683dda --- /dev/null +++ b/bindings/java/src/net/hyperic/sigar/cmd/SysInfo.java @@ -0,0 +1,119 @@ +package net.hyperic.sigar.cmd; + +import net.hyperic.sigar.Mem; +import net.hyperic.sigar.Swap; +import net.hyperic.sigar.SigarException; + +import java.io.File; +import java.io.FilenameFilter; +import java.io.FileReader; +import java.io.BufferedReader; +import java.io.IOException; + +/** + * Display System Information + */ +public class SysInfo extends SigarCommandBase { + + public SysInfo(Shell shell) { + super(shell); + } + + public SysInfo() { + super(); + } + + public String getUsageShort() { + return "Display system information"; + } + + public void output(String[] args) throws SigarException { + String osName = System.getProperty("os.name"); + + /** + * OS info + */ + this.out.println(osName + " " + + System.getProperty("os.version") + " " + + System.getProperty("os.arch")); + + /** + * craziness to try to determine the linux distro + */ + if (osName.equals("Linux")) { + File etc = new File("/etc"); + File[] release = etc.listFiles(new FilenameFilter() + { + public boolean accept(File dir, String name) + { + boolean distroFile = + name.toLowerCase().matches(".*elease.*"); + if (!distroFile) { + distroFile = name.toLowerCase().matches(".*ersion.*"); + } + return distroFile; + } + }); + + if (release.length != 1) { + this.out.println("Cannot determine Linux distribution!"); + if (release.length > 1) { + this.out.println("Possible version files:"); + for (int i = 0 ; i < release.length ; i++) { + this.out.println(" " + release[i]); + } + } + } + else { + try { + //this.out.println(release[0].getAbsoluteFile() + ":"); + BufferedReader rel = new BufferedReader( + new FileReader(release[0])); + String line; + while ((line = rel.readLine()) != null) { + this.out.println(line); + } + } + catch (IOException e) { + this.out.println("Cannot determine Linux distribution!"); + } + } + } + + /** + * JVM info + */ + this.out.println(System.getProperty("java.vm.name") + " - " + + System.getProperty("java.vm.vendor") + " [" + + System.getProperty("java.vm.version") + "]"); + this.out.println(System.getProperty("java.specification.vendor") + " " + + System.getProperty("java.specification.name") + " " + + System.getProperty("java.specification.version")); + this.out.println("JAVA_HOME=" + System.getProperty("java.home")); + this.out.println(""); + + /** + * CPU info + */ + net.hyperic.sigar.CpuInfo[] infos = + this.sigar.getCpuInfoList(); + for (int i=0; i