FileDocCategorySizeDatePackage
LinuxSystemInfoCollector.javaAPI DocGlassfish v2 API10489Fri May 04 22:34:44 BST 2007com.sun.enterprise.diagnostics.collect

LinuxSystemInfoCollector

public class LinuxSystemInfoCollector extends Object implements Collector
Class to collect System Information for Linux OS

Fields Summary
private static Logger
logger
private static final String
SWAP_SPACE_CMD
private static final String
TCP_SETTINGS_CMD
private static final String
MEMORY_INFO_CMD
private static final String
PROCESSOR_INFO_CMD
private static final String
HARD_DISK_INFO_CMD
private static final String
NETWORK_SETTINGS_CMD
private static final String
IP_ADDRESS_INFO_CMD
private static final String
OS_LEVEL_PATCH_INFO_CMD
private static final String
HOST_NAME_CMD
private static final String
DOMAIN_NAME_CMD
private static final String
SOFT_FILE_DESC_LIMIT_CMD
private static final String
HARD_FILE_DESC_LIMIT_CMD
private String
destFolder
Constructors Summary
public LinuxSystemInfoCollector(String destFolder)



      
        this.destFolder = destFolder;
    
Methods Summary
public com.sun.enterprise.diagnostics.Datacapture()
captures the System Information for Linux OS

return
Data


        FileData data = null;
        String outputFileName = destFolder + File.separator + Defaults.SYSTEM_INFO_FILE;


        final String ALL_CMDS = "( echo HOSTNAME  ; " + HOST_NAME_CMD + " " +
                ";echo DOMAINNAME   ; "+ DOMAIN_NAME_CMD +
                ";echo 'HARD DISK INFO'  ; " + HARD_DISK_INFO_CMD +
                ";echo 'NETWORK SETTINGS '  ; " + NETWORK_SETTINGS_CMD +
                ";echo 'IP ADDRESS INFO'  ; " + IP_ADDRESS_INFO_CMD +
                ";echo 'OS LEVEL PATCH'  ; " + OS_LEVEL_PATCH_INFO_CMD +
                ";echo 'SOFT FILE DESCRIPTOR LIMIT';"+ SOFT_FILE_DESC_LIMIT_CMD +
                ";echo 'HARD FILE DESCRIPTOR LIMIT';"+ HARD_FILE_DESC_LIMIT_CMD +
                ") >>  " + outputFileName ;

        String[] cmd = {"sh", "-c", ALL_CMDS};

        ProcessExecutor executor = new ProcessExecutor(cmd, 0);
        try{
        executor.execute();

        File outputFile = new File(outputFileName);

        FileWriter writer = new FileWriter(outputFile, true);

            String swapSpaceInfo = getSwapSpaceInfo();

            writer.write("SWAP SPACE\n");
            writer.write(swapSpaceInfo + "\n");

            String processorInfo = getProcessorInfo();

            writer.write("PROCESSOR INFO\n");
            writer.write(processorInfo + "\n");

            String memoryInfo = getMemoryInfo();

            writer.write("MEMORY INFO\n");
            writer.write(memoryInfo + "\n");

            writer.close();

            data = new FileData(outputFile.getName(),DataType.SYSTEM_INFO);

        }
        catch(ProcessExecutorException pee){
            logger.log(Level.WARNING, "Exception while capturing system info" +
                     " : " + pee.getMessage());
        }
        catch(FileNotFoundException fnfe){
            logger.log(Level.WARNING, "Exception while capturing system info" +
                     " : " + fnfe.getMessage());
        }
        catch(IOException ioe){
            logger.log(Level.WARNING, "Exception while capturing system info" +
                     " : " + ioe.getMessage());
        }
        return data;
    
public java.lang.StringgetMemoryInfo()
To get memory information

return
String representing memory information

        String result = null;
        try {
            File file = new File(MEMORY_INFO_CMD); //file holding swap details
            BufferedReader reader = new BufferedReader(new FileReader(file));


            String line = null; //to read a line from the file
            String total = null; //total swap space
            String used = null;  //used space
            String free = null;  //free space

            while (true) {
                line = reader.readLine();
                if (line != null && line.indexOf("Mem:") >= 0) {
                    StringTokenizer tokenizer = new StringTokenizer(line, " ");

                    if (tokenizer.countTokens() >= 4)
                    // Tokenize and get individual strings
                    {
                        tokenizer.nextElement();
                        total = (String) tokenizer.nextElement();
                        used = (String) tokenizer.nextElement();
                        free = (String) tokenizer.nextElement();

                        result = "Total : " + total + "\nUsed : " + used +
                                "\nFree : " + free;
                    }
                    break;

                } else if (line == null) // exit when eof is reached
                {
                    break;
                }
            }
            reader.close();
        }
        catch (IOException ioe) {

            logger.log(Level.WARNING, "Exception while retrieving Memory " +
                    "Info : " + ioe.getMessage());
        }
        return result;
    
public java.lang.StringgetProcessorInfo()
To get Processor Information

return
String representing processor information

        String result = null;
        try {
            File file = new File(PROCESSOR_INFO_CMD); //file holding CPU details
            BufferedReader reader = new BufferedReader(new FileReader(file));

            String line = null; //to read a line from the file

            while (true) {
                line = reader.readLine();
                if (line != null && line.indexOf("model name") >= 0) {
                    int index = line.indexOf(":");
                    if (index >= 0) {
                        result = line.substring(index + 1);
                    }
                    break;
                } else if (line == null) // exit when eof is reached
                {
                    break;
                }
            }
            reader.close();
        }
        catch (IOException ioe) {

            logger.log(Level.WARNING,"Exception while retrieving Processor Info" +
                    " : " + ioe.getMessage());
        }
        return result;
    
public java.lang.StringgetSwapSpaceInfo()
to get the Swap Space Information

return
String representing swap space information

        String result = null;

        try {
            File file = new File(SWAP_SPACE_CMD); //file holding swap details
            BufferedReader reader = new BufferedReader(new FileReader(file));

            String line = null; //represents one line in the file
            String total = null; //total swap space
            String used = null;  //used space
            String free = null;  //free space

            while (true) {
                line = reader.readLine();
                if (line != null && line.indexOf("Swap:") >= 0) {
                    StringTokenizer tokenizer = new StringTokenizer(line, " ");

                    if (tokenizer.countTokens() >= 4) // Tokenize and get
                                                      // individual strings
                    {
                        tokenizer.nextElement();
                        total = (String) tokenizer.nextElement();
                        used = (String) tokenizer.nextElement();
                        free = (String) tokenizer.nextElement();

                        result = "Total : " + total + " , " + " Used : " + used +
                                " , " + "Free : " + free;
                    }
                    break;
                } else if (line == null) // exit when eof is reached
                {
                    break;
                }
            }
            reader.close();
        }
        catch (IOException ioe) {

           logger.log(Level.WARNING, "Exception while retrieving Swap Space Info" +
                    " : " + ioe.getMessage());
        }
        return result;