001: /**
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */package org.apache.geronimo.management.geronimo.stats;
017:
018: import javax.management.j2ee.statistics.CountStatistic;
019: import javax.management.j2ee.statistics.RangeStatistic;
020: import javax.management.j2ee.statistics.TimeStatistic;
021:
022: import org.apache.geronimo.management.stats.StatsImpl;
023: import org.apache.geronimo.management.stats.StatisticImpl;
024: import org.apache.geronimo.management.stats.CountStatisticImpl;
025: import org.apache.geronimo.management.stats.RangeStatisticImpl;
026: import org.apache.geronimo.management.stats.BoundedRangeStatisticImpl;
027: import org.apache.geronimo.management.stats.TimeStatisticImpl;
028:
029: /**
030: * Geronimo implementation of the JSR-77 style WebConnectorStats interface. This
031: * is not required by JSR-77, but provides useful statistics. This will be
032: * discovered by mejb using 'stats' attribute.
033: *
034: * @version $Revision: 581936 $ $Date: 2007-10-04 07:46:56 -0700 (Thu, 04 Oct 2007) $
035: */
036:
037: public class TomcatWebConnectorStatsImpl extends StatsImpl implements
038: TomcatWebConnectorStats {
039: private TimeStatisticImpl requestTime; // total, max, count
040:
041: private CountStatisticImpl activeRequestCount;
042:
043: private CountStatisticImpl errorCount;
044:
045: private CountStatisticImpl bytesSentCount;
046:
047: private CountStatisticImpl bytesReceivedCount;
048:
049: // these come from ThreadPool
050: private RangeStatisticImpl openConnectionCount;
051:
052: private CountStatisticImpl busyThreadCount;
053:
054: // TODO - change the name to BoundedRangeStatisticsImpl
055: private BoundedRangeStatisticImpl busyThreads;
056:
057: // TODO - spareThreads metrics = current - busy, maxSpareThreads, minSpareThreads
058:
059: public TomcatWebConnectorStatsImpl() {
060: requestTime = new TimeStatisticImpl("Request Time",
061: StatisticImpl.UNIT_TIME_MILLISECOND,
062: "The time to process all requests");
063: activeRequestCount = new CountStatisticImpl(
064: "Active Request Count", StatisticImpl.UNIT_COUNT,
065: "currently active requests ", 0);
066: errorCount = new CountStatisticImpl("Error Count",
067: StatisticImpl.UNIT_COUNT,
068: "The numbet of Errors during the observed period", 0);
069: bytesSentCount = new CountStatisticImpl("Bytes Sent",
070: StatisticImpl.UNIT_COUNT,
071: "The number of bytes sent during the observerd period",
072: 0);
073: bytesReceivedCount = new CountStatisticImpl(
074: "Bytes Received",
075: StatisticImpl.UNIT_COUNT,
076: "The number of bytes received during the observerd period",
077: 0);
078: openConnectionCount = new RangeStatisticImpl(
079: "" + "Open Connections",
080: StatisticImpl.UNIT_COUNT,
081: "Range for connections opened during the observed period",
082: 0); // all 0's
083: busyThreads = new BoundedRangeStatisticImpl(
084: "Busy Threads",
085: StatisticImpl.UNIT_COUNT,
086: "BoundedRange for Threads currently busy serving requests",
087: 0, 0, 0);
088: addStat("RequestTime", requestTime); // better name
089: addStat("activeRequestCount", activeRequestCount);
090: addStat("errorCount", errorCount);
091: addStat("bytesSent", bytesSentCount);
092: addStat("bytesReceived", bytesReceivedCount);
093: addStat("openConnectionCount", openConnectionCount);
094: addStat("busyThreads", busyThreads);
095: }
096:
097: public RangeStatistic getActiveRequestCount() {
098: // TODO
099: return null;
100: }
101:
102: public TimeStatistic getRequestTime() {
103: return requestTime;
104: }
105:
106: public CountStatistic getErrorCount() {
107: return errorCount;
108: }
109:
110: public CountStatistic getBytesSentCount() {
111: return bytesSentCount;
112: }
113:
114: public CountStatistic getBytesReceivedCount() {
115: return bytesReceivedCount;
116: }
117:
118: public RangeStatistic getOpenConnectionCount() {
119: return openConnectionCount;
120: }
121:
122: // TODO - Move this to container statistics
123: public RangeStatistic getSpareThreadCount() {
124: return null;
125: }
126:
127: /**
128: * These setters are used by native implementation
129: */
130: public void setBytesReceivedCount(long bytesReceived) {
131: this .bytesReceivedCount.setCount(bytesReceived);
132: }
133:
134: public void setBytesSentCount(long bytesSent) {
135: this .bytesSentCount.setCount(bytesSent);
136: }
137:
138: public void setActiveRequestCount(int activeRequestCount) {
139: this .activeRequestCount.setCount(activeRequestCount);
140: }
141:
142: public void setErrorCount(int errorCount) {
143: this .errorCount.setCount(errorCount);
144: }
145:
146: public void setRequestTime(int count, long minTime, long maxTime,
147: long totalTime) {
148: this .requestTime.setCount(count);
149: this .requestTime.setMinTime(minTime);
150: this .requestTime.setMaxTime(maxTime);
151: this .requestTime.setTotalTime(totalTime);
152: }
153:
154: public void setOpenConnection(long current, long highMark,
155: long lowMark) {
156: openConnectionCount.setCurrent(current);
157: openConnectionCount.setHighWaterMark(highMark);
158: openConnectionCount.setLowWaterMark(lowMark);
159: }
160:
161: public void setBusyThreads(long current, long highWaterMark,
162: long lowWaterMark, long upperBound, long lowerBound) {
163: busyThreads.setCurrent(current);
164: busyThreads.setHighWaterMark(highWaterMark);
165: busyThreads.setLowWaterMark(lowWaterMark); //0?
166: busyThreads.setLowerBound(lowerBound); //0?
167: busyThreads.setUpperBound(upperBound); // always maxThreads
168: }
169:
170: /**
171: * Used to access the native implementation in order to call setters
172: * TODO implement these if needed by console
173: */
174: public RangeStatisticImpl getActiveRequestCountImpl() {
175: return null;
176: }
177:
178: public TimeStatisticImpl getRequestDurationImpl() {
179: return null;
180: }
181:
182: public CountStatisticImpl getTotalErrorCountImpl() {
183: return null;
184: }
185:
186: public CountStatistic getTotalRequestCountImpl() {
187: return null;
188: }
189:
190: }
|