ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/i-scream/projects/cms/source/host/java/SystemMonitor.java
Revision: 1.10
Committed: Sat May 18 18:15:57 2002 UTC (22 years, 4 months ago) by tdb
Branch: MAIN
Changes since 1.9: +21 -2 lines
Log Message:
i-scream is now licensed under the GPL. I've added the GPL headers to every
source file, and put a full copy of the license in the appropriate places.
I think I've covered everything. This is going to be a mad commit ;)

File Contents

# User Rev Content
1 tdb 1.10 /*
2     * i-scream central monitoring system
3     * Copyright (C) 2000-2002 i-scream
4     *
5     * This program is free software; you can redistribute it and/or
6     * modify it under the terms of the GNU General Public License
7     * as published by the Free Software Foundation; either version 2
8     * of the License, or (at your option) any later version.
9     *
10     * This program is distributed in the hope that it will be useful,
11     * but WITHOUT ANY WARRANTY; without even the implied warranty of
12     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13     * GNU General Public License for more details.
14     *
15     * You should have received a copy of the GNU General Public License
16     * along with this program; if not, write to the Free Software
17     * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18     */
19    
20 ab11 1.2 //---PACKAGE DECLARATION---
21    
22     //---IMPORTS---
23    
24 ab11 1.5 import java.io.*;
25 tdb 1.6 import java.net.*;
26     import java.util.*;
27 ab11 1.3
28 ab11 1.2 /**
29     * Gathers system information then outputs it as XML
30 ab11 1.9 * Collects data based on properties gained from the
31     * configurator then packages these up using XMLFormatter
32     * and outputs them if the timeout has passed.
33 ab11 1.2 *
34 tdb 1.10 * @author $Author: ab11 $
35     * @version $Id: SystemMonitor.java,v 1.9 2001/03/19 17:30:17 ab11 Exp $
36 ab11 1.2 */
37 ab11 1.1 class SystemMonitor {
38    
39 ab11 1.2 //---FINAL ATTRIBUTES---
40    
41     //---STATIC METHODS---
42    
43     //---CONSTRUCTORS---
44    
45     /**
46 ab11 1.9 * Public constructor for the class. Takes in a Config
47     * object to gain its properties from.
48 ab11 1.2 *
49     */
50     public SystemMonitor( Config config ){
51     // create a new instace, get the info we need out of config
52     // like things to monitor
53    
54     lastCheck = System.currentTimeMillis();
55 tdb 1.6 sequence = 1;
56 ab11 1.2
57     }
58    
59     //---PUBLIC METHODS---
60    
61     /**
62     * Gathers system information and will black until the timeout has passed.
63     *
64     * @return the system information in an XML packet
65     */
66     public String getInfo(){
67     // called to retrieve the stored averages and output them as a XML string
68 tdb 1.6 String host = new String();
69     String ip = new String();
70 ab11 1.5 try {
71 tdb 1.6 host = InetAddress.getLocalHost().getHostName();
72 ab11 1.9 ip = InetAddress.getLocalHost().getHostAddress();
73 tdb 1.6 } catch(UnknownHostException e) {
74     System.out.println(e);
75 ab11 1.5 }
76 ab11 1.9 String date = Long.toString(System.currentTimeMillis());
77 tdb 1.8 XMLFormatter xml = new XMLFormatter("packet", "machine_name=\""+host+"\" ip=\""+ip+"\" date=\""+date+"\" seq_no=\""+sequence+"\" type=\"data\"");
78 tdb 1.6
79 ab11 1.9 // get and decode the data
80     DecodeCPU_TXT details = new DecodeCPU_TXT();
81 tdb 1.6
82     // add the decoded info
83 ab11 1.5 xml.addString(details.getItems());
84    
85 ab11 1.2 // increment sequence.
86     sequence++;
87 ab11 1.7 // lastCheck = System.currentTimeMillis();
88 ab11 1.2
89     // finally return a string
90     return xml.returnXML();
91     } // getinfo()
92    
93     //---PRIVATE METHODS---
94    
95     //---ACCESSOR/MUTATOR METHODS---
96    
97     //---ATTRIBUTES---
98 ab11 1.1
99     private long lastCheck;
100     private int sequence;
101 ab11 1.2
102     //---STATIC ATTRIBUTES---
103 ab11 1.1
104 ab11 1.9 } // class