KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > diagnostics > collect > SolarisSystemInfoCollector


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23 package com.sun.enterprise.diagnostics.collect;
24
25 import com.sun.logging.LogDomains;
26 import com.sun.enterprise.diagnostics.Data;
27 import com.sun.enterprise.diagnostics.Defaults;
28
29 import java.io.*;
30 import java.util.logging.Level JavaDoc;
31 import java.util.logging.Logger JavaDoc;
32
33
34 /**
35  * Class to collect System Information for Solaris OS
36  */

37 public class SolarisSystemInfoCollector implements Collector {
38
39
40     private static Logger JavaDoc logger =
41             LogDomains.getLogger(LogDomains.ADMIN_LOGGER);
42
43     /* Command for properties */
44     private static final String JavaDoc HARD_DISK_INFO_CMD = "df -k | grep /dev | grep " +
45             "-v /dev/fd | awk '{print $1, $2, $6}'";
46     private static final String JavaDoc MEMORY_INFO_CMD = "/usr/sbin/prtconf | grep" +
47             " 'Memory size'";
48     private static final String JavaDoc NETWORK_SETTINGS_CMD = "ifconfig -a | egrep" +
49             " '^hme|^qfe' | awk '{print $1, $2, $6}'";
50     private static final String JavaDoc TCP_SETTINGS_CMD = "ndd /dev/tcp " +
51             "tcp_time_wait_interval";
52     private static final String JavaDoc IP_ADDRESS_INFO_CMD = "netstat -in |" +
53             " /usr/xpg4/bin/grep -Ev 'Name|lo0' | awk '{print $4}'";
54     private static final String JavaDoc OS_LEVEL_PATCH_INFO_CMD = "showrev -p";
55     private static final String JavaDoc HOST_NAME_CMD = "hostname";
56     private static final String JavaDoc DOMAIN_NAME_CMD = "domainname";
57     private static final String JavaDoc SOFT_FILE_DESC_LIMIT_CMD = "ulimit -n";
58     private static final String JavaDoc HARD_FILE_DESC_LIMIT_CMD = "ulimit -Hn";
59     private static final String JavaDoc PROCESSOR_INFO_CMD = "psrinfo -v | grep " +
60             "'processor operates at'";
61     private static final String JavaDoc SWAP_INFO_CMD = "swap -s";
62     private String JavaDoc destFolder = null;
63     
64
65     public SolarisSystemInfoCollector(String JavaDoc destFolder){
66         this.destFolder = destFolder;
67     }
68
69     /**
70      * To capture the system information for solaris OS
71      * @return Data representing System Information
72      * @return Data representing System Information
73      */

74     public Data capture(){
75
76         FileData data = null;
77
78         String JavaDoc outputFileName = destFolder + File.separator + Defaults.SYSTEM_INFO_FILE;
79
80         final String JavaDoc ALL_CMDS =
81                 "( " +
82                 " echo 'HOST NAME' ; "+ HOST_NAME_CMD +
83                 " ; echo 'DOMAIN NAME' ; "+DOMAIN_NAME_CMD +
84                 " ; echo 'HARD DISK INFO ' ; "+HARD_DISK_INFO_CMD +
85                 " ; echo 'NETWORK CONFIGURATION ' ; "+NETWORK_SETTINGS_CMD +
86                 " ; echo 'IP ADDRESS ' ; "+ IP_ADDRESS_INFO_CMD +
87                 " ; echo 'OS LEVEL PATCH INFO' ; "+OS_LEVEL_PATCH_INFO_CMD +
88                 " ; echo 'SOFT FILE DESCRIPTOR LIMIT ' ; "+SOFT_FILE_DESC_LIMIT_CMD +
89                 " ; echo 'HARD FILE DESCRIPTOR LIMIT ' ; "+HARD_FILE_DESC_LIMIT_CMD +
90                 " ; echo 'PROCESSOR INFO' ; "+PROCESSOR_INFO_CMD +
91                 " ; echo 'SWAP SPACE' ; "+SWAP_INFO_CMD +
92                 " ; echo 'MEMORY INFO ' ; " + MEMORY_INFO_CMD +
93                 " ) >> "+ outputFileName ;
94
95         String JavaDoc[] cmd = {"sh", "-c", ALL_CMDS};
96
97         ProcessExecutor executor = new ProcessExecutor(cmd, 0);
98         try{
99         executor.execute();
100
101         File outputFile = new File(outputFileName);
102
103          data = new FileData(outputFile.getName(),DataType.SYSTEM_INFO);
104         }
105         catch(ProcessExecutorException pee){
106             logger.log(Level.WARNING, "Exception while capturing system info" +
107                      " : " + pee.getMessage());
108         }
109         return data;
110     }
111 }
112
Popular Tags