001: /*
002: * <copyright>
003: *
004: * Copyright 1997-2004 BBNT Solutions, LLC
005: * under sponsorship of the Defense Advanced Research Projects
006: * Agency (DARPA).
007: *
008: * You can redistribute this software and/or modify it under the
009: * terms of the Cougaar Open Source License as published on the
010: * Cougaar Open Source Website (www.cougaar.org).
011: *
012: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
013: * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
014: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
015: * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
016: * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
017: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
018: * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
019: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
020: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
021: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
022: * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
023: *
024: * </copyright>
025: */
026:
027: package org.cougaar.core.qos.metrics;
028:
029: import java.io.PrintWriter;
030: import java.text.DecimalFormat;
031:
032: import javax.servlet.http.HttpServletRequest;
033:
034: import org.cougaar.core.component.ServiceBroker;
035:
036: /**
037: * This Servlet displays the Host resource metrics, using the Node to
038: * get at it.
039: */
040: public class NodeResourcesServlet extends MetricsServlet implements
041: Constants {
042: public NodeResourcesServlet(ServiceBroker sb) {
043: super (sb);
044: }
045:
046: public String getPath() {
047: return "/metrics/resources";
048: }
049:
050: public String getTitle() {
051: return "Resources for Node " + getNodeID();
052: }
053:
054: private void outputMetric(PrintWriter out, String path,
055: String name, double ignore, double highlight,
056: boolean greater, DecimalFormat formatter) {
057: Metric metric = metricsService.getValue(path + name);
058: if (metric == null)
059: metric = new MetricImpl(new Double(0.00), 0, "units",
060: "test");
061: out.print("<tr><td>");
062: out.print(name);
063: out.print("</td>");
064: ServletUtilities.valueTable(metric, ignore, highlight, greater,
065: formatter, out);
066: out.print("</tr>\n");
067: }
068:
069: public void printPage(HttpServletRequest request, PrintWriter out) {
070: String nodePath = "Agent(" + getNodeID() + ")" + PATH_SEPR;
071:
072: // Space between the intro and the content
073: out.print("<br><br>");
074:
075: //Header Row
076: out.print("<table border=3 rules=groups>\n");
077: out.print("<colgroup><colgroup>");
078: out.print("<tr>");
079: out.print("<th>RESOURCE</th>");
080: out.print("<th>Value</th>");
081: out.print("</tr>");
082:
083: //Rows
084: outputMetric(out, nodePath, "EffectiveMJips", 10.0, 400.0,
085: false, f2_0);
086: outputMetric(out, nodePath, "LoadAverage", 0.0, 4.0, true, f4_2);
087: outputMetric(out, nodePath, "Count", 1.0, 5.0, true, f2_0);
088: outputMetric(out, nodePath, "Jips", 1.0, 400000000.0, false,
089: f7_0);
090: outputMetric(out, nodePath, "BogoMips", 1.0, 800.0, false, f7_0);
091: outputMetric(out, nodePath, "Cache", 1.0, 256, false, f7_0);
092: outputMetric(out, nodePath, "TcpInUse", 0.0, 50.0, true, f3_0);
093: outputMetric(out, nodePath, "UdpInUse", 0.0, 50.0, true, f3_0);
094: outputMetric(out, nodePath, "TotalMemory", 0.0, 256000.0,
095: false, f7_0);
096: outputMetric(out, nodePath, "FreeMemory", 0.0, 32000, false,
097: f7_0);
098: outputMetric(out, nodePath, "MeanTimeBetweenFailure", 1.0,
099: 1000.0, false, f7_0);
100:
101: out.print("</table>");
102: }
103: }
|