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.mts.std;
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: import org.cougaar.core.mts.MessageStatistics;
036: import org.cougaar.core.service.MessageStatisticsService;
037: import org.cougaar.core.servlet.ServletFrameset;
038:
039: /**
040: * This Servlet uses the {@link MessageStatistics} to display message
041: * size and count statistics for the Node. It's created by the {@link
042: * StatisticsPlugin}.
043: */
044: public class StatisticsServlet extends ServletFrameset {
045:
046: private final DecimalFormat f4_2 = new DecimalFormat("#0.00");
047:
048: private MessageStatisticsService statisticsService;
049:
050: public StatisticsServlet(ServiceBroker sb) {
051: super (sb);
052: statisticsService = (MessageStatisticsService) sb.getService(
053: this , MessageStatisticsService.class, null);
054: }
055:
056: public String getPath() {
057: return "/message/statistics";
058: }
059:
060: public String getTitle() {
061: return getNodeID() + " Message Statistics";
062: }
063:
064: public void printPage(HttpServletRequest request, PrintWriter out) {
065: String reset_string = request.getParameter("reset");
066: boolean reset = reset_string != null
067: && reset_string.equalsIgnoreCase("true");
068:
069: MessageStatistics.Statistics stats = null;
070: if (statisticsService == null) {
071: out.print("<p><b>");
072: out
073: .print("ERROR: Message Statistics Service is not Available\n");
074: out.print("</b><p> org.cougaar.mts.std.StatisticsAspect ");
075: out.print("should be loaded into Node \n");
076: return;
077: } else {
078: stats = statisticsService.getMessageStatistics(reset);
079: if (stats == null) {
080: out.print("<p><b>");
081: out
082: .print("ERROR: Message Statistics Service returned null statistics\n");
083: return;
084: }
085: }
086: out
087: .print("<h2>Messages sent and received by all agents on node ");
088: out.print(getNodeID());
089: out.println("</h2>");
090: out.print("<table border=1>\n");
091: out.print("<tr><b>");
092: out.print("<td><b></b></td>");
093: out.print("<td><b>Sent</b></td>");
094: out.print("<td><b>Received</b></td>");
095: out.print("</b></tr>");
096:
097: out.print("<tr><b>");
098: out.print("<td><b>Avg Queue Length</b></td>");
099: out.print("<td><b>");
100: out.print(f4_2.format(stats.averageMessageQueueLength));
101: out.print("</b></td>");
102: out.print("<td><b>");
103: out.print("NA");
104: out.print("</b></tr>");
105: out.print("<tr><b>");
106: out.print("<td><b>Total Message Bytes</b></td>");
107: out.print("<td><b>");
108: out.print(stats.totalSentMessageBytes);
109: out.print("</b></td>");
110: out.print("<td><b>");
111: out.print(stats.totalRecvMessageBytes);
112: out.print("</b></td>");
113: out.print("</b></tr>");
114: out.print("<tr><b>");
115: out.print("<td><b>Total Header Bytes</b></td>");
116: out.print("<td><b>");
117: out.print(stats.totalSentHeaderBytes);
118: out.print("</b></td>");
119: out.print("<td><b>");
120: out.print(stats.totalRecvHeaderBytes);
121: out.print("</b></td>");
122: out.print("</b></tr>");
123: out.print("<tr><b>");
124: out.print("<td><b>Total Ack Bytes</b></td>");
125: out.print("<td><b>");
126: out.print(stats.totalSentAckBytes);
127: out.print("</b></td>");
128: out.print("<td><b>");
129: out.print(stats.totalRecvAckBytes);
130: out.print("</b></td>");
131: out.print("</b></tr>");
132: out.print("<tr><b>");
133: out.print("<td><b>Total Bytes</b></td>");
134: out.print("<td><b>");
135: out.print(stats.totalSentMessageBytes
136: + stats.totalSentHeaderBytes + stats.totalSentAckBytes);
137: out.print("</b></td>");
138: out.print("<td><b>");
139: out.print(stats.totalRecvMessageBytes
140: + stats.totalRecvHeaderBytes + stats.totalRecvAckBytes);
141: out.print("</b></td>");
142: out.print("</b></tr>");
143: out.print("<tr><b>");
144: out.print("<td><b>Total Intra-node Messages</b></td>");
145: out.print("<td><b>");
146: out.print(stats.histogram[0]);
147: out.print("</b></td>");
148: out.print("<td><b>");
149: out.print(stats.histogram[0]);
150: out.print("</b></td>");
151: out.print("</b></tr>");
152: out.print("<tr><b>");
153: out.print("<td><b>Total Message Count</b></td>");
154: out.print("<td><b>");
155: out.print(stats.totalSentMessageCount);
156: out.print("</b></td>");
157: out.print("<td><b>");
158: out.print(stats.totalRecvMessageCount);
159: out.print("</b></td>");
160: out.print("</b></tr>");
161:
162: out.println("</table>");
163:
164: out.print("<p><h2>Sent Message Length Histogram</h2>");
165: out.print("<table border=1>\n");
166: out.print("<tr><b>");
167: out.print("<td><b>Size</b></td>");
168: out.print("<td><b>Count</b></td>");
169: out.print("</b></tr>");
170:
171: for (int i = 1; i < stats.histogram.length; i++) {
172: out.print("<tr><b>");
173:
174: out.print("<td><b>");
175: out.print(MessageStatistics.BIN_SIZES[i]);
176: out.print("</b></td>");
177:
178: out.print("<td><b>");
179: out.print(stats.histogram[i]);
180: out.print("</b></td>");
181:
182: out.print("</b></tr>");
183: }
184: out.print("</table>");
185: }
186: }
|