ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/i-scream/projects/cms/source/host/java/SystemMonitor.java
Revision: 1.11
Committed: Tue May 21 16:47:12 2002 UTC (22 years, 6 months ago) by tdb
Branch: MAIN
Changes since 1.10: +3 -2 lines
Log Message:
Added URL to GPL headers.

File Contents

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