GridLab
Grid Application Toolkit

A simple API for Grid Applications
GAT

Menu



Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members  

Metric.java

Go to the documentation of this file.
00001 package org.gridlab.gat.monitoring;
00002 
00003 import java.util.Map;
00004 
00005 /**
00006  * An instance of this class represents a measurable quantity within a monitoring 
00007  * system.There are two classes of metrics a monitoring system must deal with:
00008  * <ul>
00009  * <li> <em>Local metrics</em> --- Local metrics are metrics that are directly 
00010  * measured on a resource. These can be highly dependent on the physical parameters 
00011  * of the resource. Thus, local metrics originating from two different resources 
00012  * are not necessarily comparable ( E.g. 1 hour CPU time on a 1 GHz Intel processor
00013  * is different than 1 hour CPU time on an 800 MHz PPC processor although the numeric 
00014  * values are equal.) However resource administrators who know the configuration of 
00015  * the resource need local metrics for detailed monitoring of the status and operation 
00016  * of the resource.</li>
00017  * <li> <em>Grid metrics</em> ---  Grid metrics are metrics that have predefined 
00018  * semantics thus, they are resource independent. Grid metrics are derived from one or 
00019  * more local metrics by applying a specific, well defined algorithm (such as unit 
00020  * conversion, aggregation or averaging). Because of this transformation grid metrics 
00021  * may have less precision or they could be less specific but are guaranteed to be 
00022  * comparable between different resources. Unlike local metrics which a local resource 
00023  * is free to change grid metrics must be agreed upon, standardised and introduced by 
00024  * community consensus.</li>
00025  * </ul>
00026  * Instances of this class deal with both classes of metrics.
00027  * <p>
00028  * A Metric can only be measured if there exists a sensor which can measure the quantity
00029  * corresponding to the Metric. Such sensors are created by sensor developers and must 
00030  * embedded in a resource to allow the corresponding Metric or Metrics to be measured. 
00031  * (The creation of sensors is beyond the scope of this document and as such will not 
00032  * be covered.) Such sensors, once created, define the Metric or Metrics which they 
00033  * allow to be measured using a metric definitions.
00034  * <p>
00035  * A metric definition contains the following information:
00036  * <ul>
00037  * <li> Metric name</li>
00038  * <li> Metric parameters</li>
00039  * <li> Metric measurement type</li>
00040  * <li> Metric data type</li>
00041  * <li> Metric Unit</li>
00042  * </ul>
00043  * <p>
00044  * <em>Metric name</em> The Metric name is used to identify the metric definition (e.g.
00045  * CPU usage). It consists of dot separated words, e.g. host.cpu.user. The last 
00046  * component of a metric name is the actual name of the metric, the preceding components
00047  * are called scope. The scope can be used to group metrics as well as to differentiate 
00048  * between similar metrics defined at different levels (for example, CPU utilisation 
00049  * can be measured on a per-job or per-host level).
00050  * <p>
00051  * <em>Metric parameters</em> The Metric parameters field in the metric definition 
00052  * contains the formal definition of the metric parameters. Many metrics can be 
00053  * measured at different places simultaneously. For example, CPU utilisation can be 
00054  * measured on several hosts or grid resources. The metric parameters can be used to 
00055  * distinguish between these different metric instances.
00056  * <p>
00057  * <em>Metric measurement type</em> The Metric Measurement type can be 
00058  * <it>continuous</it> meaning  data is always available or <it>event-like</it> meaning 
00059  * data only becomes available when some external event happens  (e.g. a sensor embedded
00060  * in an application can send events any time). Continuous metrics are only available 
00061  * using pull model delivery unless the user specifies a measurement frequency. (The 
00062  * reason for this is without a specified measurement frequency there is no event 
00063  * triggering the measurement of a continuous metric.) If the user asks for periodic 
00064  * measurements by specifying a measurement frequency the system will generate periodic 
00065  * events automatically. This avoids polling and allows the system to use the
00066  * measurement frequency information to optimise measurements.
00067  * <p>
00068  * <em>Metric data type</em> The Metric data type contains the definition of the 
00069  * storage used for representing measurement data. 
00070  * <p>
00071  * <em>Metric Unit</em> The Metric unit specifies the physical unit in which the metric 
00072  * is measured as a java.lang.String. It is only valid for simple numeric types and 
00073  * java.util.List's of these types. In the latter case it means the  unit of all 
00074  * elements of the java.util.List.
00075  * <p>
00076  * In using the Metric class one must make an instance of the Metric class. One does 
00077  * so using the Metric constructor; it takes the Metric name and concrete values for 
00078  * the Metric parameters and yields a Metric instance. The notion of Metric instances 
00079  * is necessary because the same metric could be measured at different places (e.g. 
00080  * on different hosts) at the same time. Metric instances are used to differentiate 
00081  * between these measurements, e.g. instances of a Metric describing the available 
00082  * memory on a host are distinguished by a parameter containing the hostname.
00083  */
00084 public class Metric
00085 {
00086     /**
00087      * This member variable holds the Metric name
00088      */
00089     private String metricName = null;
00090     
00091     /**
00092      * This member variable holds the Metric parameters
00093      */
00094     private Map metricParameters = null;
00095      
00096     /**
00097      * Constructs a Metric instance from the passed Metric name and concrete values 
00098      * for the Metric parameters.
00099      * <p>
00100      * The passed Metric name must be equal, as determined by the Equals method of the 
00101      * java.lang.String class, to the Metric name is the desired target Metric 
00102      * definition. In addition, the passed concrete values for the Metric parameters 
00103      * must be of the same name and type as the Metric parameters in the desired target 
00104      * Metric definition. Also, all the required Metric parameters as specified in the 
00105      * Metric definition must be present. 
00106      *
00107      * @param metricName The Metric name, a java.lang.String, of the desired target 
00108      * Metric definition
00109      * @param metricParameters The Metric parameters, a java.util.Map, for the desired 
00110      * Metric definition
00111      */
00112     public Metric(String metricName, Map metricParameters) {
00113         this.metricName = metricName;
00114         this.metricParameters = metricParameters;
00115     }
00116     
00117     /**
00118      * Tests this Metric for equality with the passed Object.
00119      * <p>
00120      * If the given object is not a Metric, then this method immediately returns false. 
00121      * <p>
00122      * For two Metric instances to be considered as equal they must have equal Metric 
00123      * names, a java.lang.String, as determined my the Equals method on java.lang.String.
00124      * In addition, they must have equal Metric parameters as determined by the Equals 
00125      * method on java.util.Map.
00126      *
00127      * @param object The Object to test for equality 
00128      * @return A boolean indicating equality
00129      */
00130     public boolean equals(Object object) {
00131       Metric metric = null;
00132         
00133       if( false == (object instanceof Metric) ) {
00134     return false;
00135       }
00136       metric = (Metric) object;
00137         
00138       if( false == metricName.equals(metric.metricName) ) {
00139     return false;
00140       }
00141       if( false == metricParameters.equals(metric.metricParameters) ) {
00142     return false;
00143       }
00144       return true;
00145   }
00146     
00147     /**
00148      * Gets the Metric name associated with this Metric.
00149      *
00150      * @return The Metric name, a java.lang.String
00151      */
00152     public String  getMetricName() {
00153       return metricName;
00154   }
00155     
00156     /**
00157      * Gets the Metric parameters associated with this Metric.
00158      *
00159      * @return The Metric parameters, a java.util.Map
00160      */
00161     public Map getMetricParameters() {
00162       return metricParameters;
00163   }
00164     
00165     /**
00166      * Gets the Metric parameter value associated with the passed Metric parameter 
00167      * name. The value null is returned if there is no Metric parameter value with 
00168      * the passed name.  
00169      *
00170      * @param name The Metric parameter name, a java.lang.String, for which to obtain 
00171      * the associated Metric
00172      * @return The Metric parameter value, an Object, associated with the passed Metric 
00173      * parameter name.
00174      */
00175     public Object getMetricParameterByName(String name) {
00176       return metricParameters.get(name);
00177   }
00178 }