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.util.Iterator;
031:
032: import javax.servlet.http.HttpServletRequest;
033:
034: import org.cougaar.core.component.ServiceBroker;
035: import org.cougaar.core.mts.AgentStatusService;
036: import org.cougaar.core.mts.MessageAddress;
037:
038: /**
039: * This Servlet collects cpu and message metrics for each local Agent
040: * and displays the result in a nicely formatted web page. In the <a
041: * href="../../../../../../OnlineManual/MetricsService/sensors.html">Sensor
042: * Data Flow</a> pattern this class plays the role of <b>Servlet</b>
043: * for load data (CPU load average, CPU) and messages sizes and counts
044: * for Agents, Nodes and Services.
045: *
046: * @see org.cougaar.core.thread.AgentLoadRatePlugin
047: * @see org.cougaar.core.thread.AgentLoadSensorPlugin
048: * @see AgentStatusService
049: * @see AgentStatusRatePlugin
050: */
051: public class AgentLoadServlet extends MetricsServlet implements
052: Constants {
053: private AgentStatusService agentStatusService;
054:
055: public AgentLoadServlet(ServiceBroker sb) {
056: super (sb);
057:
058: agentStatusService = (AgentStatusService) sb.getService(this ,
059: AgentStatusService.class, null);
060: }
061:
062: public String getPath() {
063: return "/metrics/agent/load";
064: }
065:
066: public String getTitle() {
067: return "Agent Load for Node " + getNodeID();
068: }
069:
070: public void printRow(MessageAddress name, String type,
071: PrintWriter out) {
072: String sizeFormula = null;
073: String label = name.getAddress();
074:
075: if (type.equals("Agent")) {
076: sizeFormula = PERSIST_SIZE_LAST;
077: } else {
078: sizeFormula = "VMSize";
079: }
080:
081: String path = type + "(" + name + ")" + PATH_SEPR;
082: // Get Metrics
083: Metric cpuLoad = metricsService.getValue(path + CPU_LOAD_AVG
084: + "(" + _10_SEC_AVG + ")");
085:
086: Metric cpuLoadJips = metricsService.getValue(path
087: + CPU_LOAD_MJIPS + "(" + _10_SEC_AVG + ")");
088: Metric msgIn = metricsService.getValue(path + MSG_IN + "("
089: + _10_SEC_AVG + ")");
090: Metric msgOut = metricsService.getValue(path + MSG_OUT + "("
091: + _10_SEC_AVG + ")");
092: Metric bytesIn = metricsService.getValue(path + BYTES_IN + "("
093: + _10_SEC_AVG + ")");
094: Metric bytesOut = metricsService.getValue(path + BYTES_OUT
095: + "(" + _10_SEC_AVG + ")");
096: Metric size = metricsService.getValue(path + sizeFormula);
097:
098: //output Row
099: out.print("<tr><td>");
100: out.print(label);
101: out.print("</td>");
102: ServletUtilities.valueTable(cpuLoad, 0.0, 1.0, true, f4_2, out);
103: ServletUtilities.valueTable(cpuLoadJips, 0.0, 200, true, f6_3,
104: out);
105: ServletUtilities.valueTable(msgIn, 0.0, 1.0, true, f4_2, out);
106: ServletUtilities.valueTable(msgOut, 0.0, 1.0, true, f4_2, out);
107: ServletUtilities.valueTable(bytesIn, 0.0, 10000, true, f7_0,
108: out);
109: ServletUtilities.valueTable(bytesOut, 0.0, 10000, true, f7_0,
110: out);
111: ServletUtilities.valueTable(size, 0.0, 10000, true, f7_0, out);
112: out.print("</tr>\n");
113: }
114:
115: private void printServiceRow(String key, PrintWriter out) {
116: out.print("<tr><td>");
117: out.print(key);
118: out.print("</td>");
119: String load_path = "Service(" + key + ")" + PATH_SEPR
120: + CPU_LOAD_AVG + "(" + _10_SEC_AVG + ")";
121: Metric load = metricsService.getValue(load_path);
122: ServletUtilities.valueTable(load, 0.0, 1.0, true, f4_2, out);
123: String jips_path = "Service(" + key + ")" + PATH_SEPR
124: + CPU_LOAD_MJIPS + "(" + _10_SEC_AVG + ")";
125: Metric jips = metricsService.getValue(jips_path);
126: ServletUtilities.valueTable(jips, 0.0, 500.0, true, f6_3, out);
127: out.print("</tr>\n");
128: }
129:
130: public void printPage(HttpServletRequest request, PrintWriter out) {
131: // Get list of All Agents On this Node
132: if (agentStatusService == null)
133: return;
134: java.util.Set localAgents = agentStatusService.getLocalAgents();
135: if (localAgents == null)
136: return;
137:
138: // Space between the intro and the content
139: out.print("<br><br>");
140:
141: //Header Row
142: out
143: .print("<table border=\"3\" cellpadding=\"2\" rules=\"groups\">\n");
144: out
145: .print("<colgroup> <colgroup span=\"2\"><colgroup span=\"4\"><colgroup>");
146: out.print("<tr><b>");
147: out.print("<th><b>NODE</b></th>");
148: out.print("<th><b>CPUloadAvg</b></th>");
149: out.print("<th><b>CPUloadMJIPS</b></th>");
150: out.print("<th><b>MsgIn</b></th>");
151: out.print("<th><b>MsgOut</b></th>");
152: out.print("<th><b>BytesIn</b></th>");
153: out.print("<th><b>BytesOut</b></th>");
154: out.print("<th><b>Size</b></th>");
155: out.print("</b></tr>");
156:
157: // Node data
158: printRow(getNodeID(), "Node", out);
159:
160: out.print("<tbody>");
161: out.print("<tr><b>");
162: out.print("<th><b>AGENTS</b></th>");
163: out.print("</b></tr>");
164:
165: //Agent Rows
166: for (Iterator itr = localAgents.iterator(); itr.hasNext();) {
167:
168: // Get Agent
169: MessageAddress addr = (MessageAddress) itr.next();
170:
171: // Print Agents Load
172: printRow(addr, "Agent", out);
173: }
174:
175: //Service table
176:
177: out.print("<tbody>");
178: out.print("<tr><b>");
179: out.print("<th><b>SERVICES</b></th>");
180: out.print("</b></tr>");
181:
182: printServiceRow("MTS", out);
183: printServiceRow("Metrics", out);
184: printServiceRow("NodeRoot", out);
185:
186: out.print("</table>");
187:
188: }
189:
190: }
|