View Javadoc
1   /*
2    * Copyright (c) 2006 Hyperic, Inc.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  
17  package org.miloss.fgsms.osagent;
18  
19  import java.util.Arrays;
20  import org.hyperic.sigar.SigarException;
21  import org.hyperic.sigar.cmd.CpuInfo;
22  import org.hyperic.sigar.cmd.Free;
23  import org.hyperic.sigar.cmd.Shell;
24  import org.hyperic.sigar.cmd.Ulimit;
25  import org.hyperic.sigar.cmd.Uptime;
26  
27  
28  import org.hyperic.sigar.cmd.Version;
29  
30  
31  /**
32   * Display System Information
33   */
34  public class SysInfo extends SigarCommandBase implements Closable{
35  
36      public SysInfo(Shell shell) {
37          super(shell);
38      }
39  
40      public SysInfo() {
41          super();
42      }
43  
44      public String getUsageShort() {
45          return "Display system information";
46      }
47  
48      public void output(String[] args) throws SigarException {
49          //sigar/os info
50          Version.printInfo(this.out);
51          println("");
52  
53          //uptime
54          new Uptime(this.shell).output(args);
55          println("");
56  
57          //cpu info
58          CpuInfo cpuinfo = new CpuInfo(this.shell);
59          cpuinfo.displayTimes = false;
60          cpuinfo.output(args);
61          println("");
62  
63          //memory info
64          new Free(this.shell).output(args);
65          println("");
66  
67          println("File Systems........." +
68                  Arrays.asList(this.sigar.getFileSystemList()));
69          println("");
70  
71          println("Network Interfaces..." +
72                  Arrays.asList(this.sigar.getNetInterfaceList()));
73          println("");
74  
75          //system resource limits
76          println("System resource limits:");
77          new Ulimit(this.shell).output(args);
78      }
79  /*
80      public static void main(String[] args) throws Exception {
81          new SysInfo().processCommand(args);
82      }*/
83          @Override
84      public void close() throws Exception{
85          if (sigar != null) {
86              sigar.close();
87              sigar = null;
88          }
89      }
90      @Override
91      protected void finalize() throws Throwable
92      {
93          
94            if (sigar != null) {
95                System.out.println("WARN,. finalize called without closing sigar first" + this.getClass().getCanonicalName());
96              sigar.close();
97          }
98          super.finalize();
99      }
100 }