| 1 | 
 //---PACKAGE DECLARATION--- | 
 
 
 
 
 
 | 2 | 
 package uk.org.iscream.client.monitors; | 
 
 
 
 
 
 | 3 | 
  | 
 
 
 
 
 
 | 4 | 
 //---IMPORTS--- | 
 
 
 
 
 
 | 5 | 
 import java.util.HashMap; | 
 
 
 
 
 
 | 6 | 
 import uk.org.iscream.client.*; | 
 
 
 
 
 
 | 7 | 
 import uk.org.iscream.core.*; | 
 
 
 
 
 
 | 8 | 
 import uk.org.iscream.util.*; | 
 
 
 
 
 
 | 9 | 
 import uk.org.iscream.componentmanager.*; | 
 
 
 
 
 
 | 10 | 
  | 
 
 
 
 
 
 | 11 | 
 /** | 
 
 
 
 
 
 | 12 | 
  * This Monitor watches the Load for all machines | 
 
 
 
 
 
 | 13 | 
  * | 
 
 
 
 
 
 | 14 | 
  * @author  $Author: tdb1 $ | 
 
 
 
 
 
 | 15 | 
  * @version $Id: Load__Monitor.java,v 1.1 2001/03/22 00:52:48 tdb1 Exp $ | 
 
 
 
 
 
 | 16 | 
  */ | 
 
 
 
 
 
 | 17 | 
 public class Load__Monitor extends MonitorSkeleton { | 
 
 
 
 
 
 | 18 | 
  | 
 
 
 
 
 
 | 19 | 
 //---FINAL ATTRIBUTES--- | 
 
 
 
 
 
 | 20 | 
  | 
 
 
 
 
 
 | 21 | 
     /** | 
 
 
 
 
 
 | 22 | 
      * The current CVS revision of this class | 
 
 
 
 
 
 | 23 | 
      */ | 
 
 
 
 
 
 | 24 | 
     public final String REVISION = "$Revision: 1.1 $"; | 
 
 
 
 
 
 | 25 | 
      | 
 
 
 
 
 
 | 26 | 
     public final String DESC = "Monitors Load."; | 
 
 
 
 
 
 | 27 | 
      | 
 
 
 
 
 
 | 28 | 
 //---STATIC METHODS--- | 
 
 
 
 
 
 | 29 | 
  | 
 
 
 
 
 
 | 30 | 
 //---CONSTRUCTORS--- | 
 
 
 
 
 
 | 31 | 
  | 
 
 
 
 
 
 | 32 | 
 //---PUBLIC METHODS--- | 
 
 
 
 
 
 | 33 | 
  | 
 
 
 
 
 
 | 34 | 
     public void analysePacket(XMLPacket packet) { | 
 
 
 
 
 
 | 35 | 
  | 
 
 
 
 
 
 | 36 | 
         String source = packet.getParam("packet.attributes.machine_name"); | 
 
 
 
 
 
 | 37 | 
         if (!_hosts.containsKey(source)) { | 
 
 
 
 
 
 | 38 | 
             HashMap attributeRegisters = new HashMap(); | 
 
 
 
 
 
 | 39 | 
             initAttributeRegsiters(source, attributeRegisters); | 
 
 
 
 
 
 | 40 | 
             _hosts.put(source, attributeRegisters); | 
 
 
 
 
 
 | 41 | 
         } | 
 
 
 
 
 
 | 42 | 
  | 
 
 
 
 
 
 | 43 | 
         HashMap attributeRegisters = (HashMap) _hosts.get(source); | 
 
 
 
 
 
 | 44 | 
         for(int attributeNum = 0; attributeNum < _attributes.length; attributeNum++) { | 
 
 
 
 
 
 | 45 | 
             Register reg = (Register) attributeRegisters.get(_attributes[attributeNum]); | 
 
 
 
 
 
 | 46 | 
             // find out the threshold level we're at | 
 
 
 
 
 
 | 47 | 
             String attribute = _attributes[attributeNum]; | 
 
 
 
 
 
 | 48 | 
             String attributeName = _attributeNames[attributeNum]; | 
 
 
 
 
 
 | 49 | 
             String currentValue = packet.getParam(attribute); | 
 
 
 
 
 
 | 50 | 
             int newThreshold = checkAttributeThreshold(currentValue, reg); | 
 
 
 
 
 
 | 51 | 
             processAlert(newThreshold, attributeName, reg, source, currentValue); | 
 
 
 
 
 
 | 52 | 
         } | 
 
 
 
 
 
 | 53 | 
  | 
 
 
 
 
 
 | 54 | 
     } | 
 
 
 
 
 
 | 55 | 
  | 
 
 
 
 
 
 | 56 | 
     /** | 
 
 
 
 
 
 | 57 | 
      * Overrides the {@link java.lang.Object#toString() Object.toString()} | 
 
 
 
 
 
 | 58 | 
      * method to provide clean logging (every class should have this). | 
 
 
 
 
 
 | 59 | 
      * | 
 
 
 
 
 
 | 60 | 
      * This uses the uk.org.iscream.util.NameFormat class | 
 
 
 
 
 
 | 61 | 
      * to format the toString() | 
 
 
 
 
 
 | 62 | 
      * | 
 
 
 
 
 
 | 63 | 
      * @return the name of this class and its CVS revision | 
 
 
 
 
 
 | 64 | 
      */ | 
 
 
 
 
 
 | 65 | 
     public String toString() { | 
 
 
 
 
 
 | 66 | 
         return FormatName.getName( | 
 
 
 
 
 
 | 67 | 
             _name, | 
 
 
 
 
 
 | 68 | 
             getClass().getName(), | 
 
 
 
 
 
 | 69 | 
             REVISION); | 
 
 
 
 
 
 | 70 | 
     } | 
 
 
 
 
 
 | 71 | 
  | 
 
 
 
 
 
 | 72 | 
     /** | 
 
 
 
 
 
 | 73 | 
      * return the String representation of what the monitor does | 
 
 
 
 
 
 | 74 | 
      */ | 
 
 
 
 
 
 | 75 | 
     public String getDescription(){ | 
 
 
 
 
 
 | 76 | 
         return DESC; | 
 
 
 
 
 
 | 77 | 
     } | 
 
 
 
 
 
 | 78 | 
  | 
 
 
 
 
 
 | 79 | 
 //---PRIVATE METHODS--- | 
 
 
 
 
 
 | 80 | 
  | 
 
 
 
 
 
 | 81 | 
     private int checkAttributeThreshold(String attributeString, Register reg) { | 
 
 
 
 
 
 | 82 | 
         for(int thresholdLevel = Alert.thresholdLevels.length - 1; thresholdLevel >= 0; thresholdLevel--) { | 
 
 
 
 
 
 | 83 | 
             if (reg.getThreshold(thresholdLevel) != -1.0) { | 
 
 
 
 
 
 | 84 | 
                 if(attributeString != null) { | 
 
 
 
 
 
 | 85 | 
                     try { | 
 
 
 
 
 
 | 86 | 
                         double attribute = Double.parseDouble(attributeString); | 
 
 
 
 
 
 | 87 | 
                         if (reg.getThreshold(thresholdLevel) < attribute) return thresholdLevel; | 
 
 
 
 
 
 | 88 | 
                     } catch (NumberFormatException e) { | 
 
 
 
 
 
 | 89 | 
                         // we got some duff data in the packet, but we shouldn't have | 
 
 
 
 
 
 | 90 | 
                         _logger.write(toString(), Logger.DEBUG, "possible errenous packet data, should be double value - " + attributeString); | 
 
 
 
 
 
 | 91 | 
                     } | 
 
 
 
 
 
 | 92 | 
                 } | 
 
 
 
 
 
 | 93 | 
             } | 
 
 
 
 
 
 | 94 | 
         } | 
 
 
 
 
 
 | 95 | 
         return Alert.thresholdNORMAL; | 
 
 
 
 
 
 | 96 | 
     } | 
 
 
 
 
 
 | 97 | 
  | 
 
 
 
 
 
 | 98 | 
     private void initAttributeRegsiters(String source, HashMap attributeRegisters) { | 
 
 
 
 
 
 | 99 | 
         for(int attributeNum = 0; attributeNum < _attributes.length; attributeNum++) { | 
 
 
 
 
 
 | 100 | 
             String attributeName = _attributes[attributeNum].substring(_attributes[attributeNum].lastIndexOf(".") + 1); | 
 
 
 
 
 
 | 101 | 
             attributeRegisters.put(_attributes[attributeNum], new Register(source, _name, attributeName)); | 
 
 
 
 
 
 | 102 | 
         } | 
 
 
 
 
 
 | 103 | 
     } | 
 
 
 
 
 
 | 104 | 
  | 
 
 
 
 
 
 | 105 | 
 //---ACCESSOR/MUTATOR METHODS--- | 
 
 
 
 
 
 | 106 | 
  | 
 
 
 
 
 
 | 107 | 
     protected Queue getQueue() { | 
 
 
 
 
 
 | 108 | 
         return MonitorManager.getInstance().getDataQueue(); | 
 
 
 
 
 
 | 109 | 
     } | 
 
 
 
 
 
 | 110 | 
  | 
 
 
 
 
 
 | 111 | 
  | 
 
 
 
 
 
 | 112 | 
 //---ATTRIBUTES--- | 
 
 
 
 
 
 | 113 | 
  | 
 
 
 
 
 
 | 114 | 
     /** | 
 
 
 
 
 
 | 115 | 
      * This is the friendly identifier of the | 
 
 
 
 
 
 | 116 | 
      * component this class is running in. | 
 
 
 
 
 
 | 117 | 
      * eg, a Filter may be called "filter1", | 
 
 
 
 
 
 | 118 | 
      * If this class does not have an owning | 
 
 
 
 
 
 | 119 | 
      * component,  a name from the configuration | 
 
 
 
 
 
 | 120 | 
      * can be placed here.  This name could also | 
 
 
 
 
 
 | 121 | 
      * be changed to null for utility classes. | 
 
 
 
 
 
 | 122 | 
      */ | 
 
 
 
 
 
 | 123 | 
     private String _name = "Load"; | 
 
 
 
 
 
 | 124 | 
      | 
 
 
 
 
 
 | 125 | 
     /** | 
 
 
 
 
 
 | 126 | 
      * A reference to the configuration proxy in use | 
 
 
 
 
 
 | 127 | 
      */ | 
 
 
 
 
 
 | 128 | 
     private ConfigurationProxy _cp = ConfigurationProxy.getInstance(); | 
 
 
 
 
 
 | 129 | 
  | 
 
 
 
 
 
 | 130 | 
     private HashMap _hosts = new HashMap(); | 
 
 
 
 
 
 | 131 | 
  | 
 
 
 
 
 
 | 132 | 
     private String[] _attributes = { "packet.load.load1", "packet.load.load5", "packet.load.load15" }; | 
 
 
 
 
 
 | 133 | 
     private String[] _attributeNames = {"1 min load avg.", "5 min load avg.", "15 min load avg."}; | 
 
 
 
 
 
 | 134 | 
  | 
 
 
 
 
 
 | 135 | 
 //---STATIC ATTRIBUTES--- | 
 
 
 
 
 
 | 136 | 
  | 
 
 
 
 
 
 | 137 | 
 } |