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 */ 017 018 package org.apache.geronimo.management.geronimo.stats; 019 020 import javax.management.j2ee.statistics.CountStatistic; 021 import javax.management.j2ee.statistics.RangeStatistic; 022 import javax.management.j2ee.statistics.TimeStatistic; 023 024 import org.apache.geronimo.management.stats.StatsImpl; 025 import org.apache.geronimo.management.stats.StatisticImpl; 026 import org.apache.geronimo.management.stats.CountStatisticImpl; 027 import org.apache.geronimo.management.stats.RangeStatisticImpl; 028 import org.apache.geronimo.management.stats.BoundedRangeStatisticImpl; 029 import org.apache.geronimo.management.stats.TimeStatisticImpl; 030 031 /** 032 * Geronimo implementation of the JSR-77 style WebConnectorStats interface. This 033 * is not required by JSR-77, but provides useful statistics. This will be 034 * discovered by mejb using 'stats' attribute. 035 * 036 * @version $Revision: 706640 $ $Date: 2008-10-21 14:44:05 +0000 (Tue, 21 Oct 2008) $ 037 */ 038 039 public class TomcatWebConnectorStatsImpl extends StatsImpl implements TomcatWebConnectorStats { 040 private TimeStatisticImpl requestTime; // total, max, count 041 042 private CountStatisticImpl activeRequestCount; 043 044 private CountStatisticImpl errorCount; 045 046 private CountStatisticImpl bytesSentCount; 047 048 private CountStatisticImpl bytesReceivedCount; 049 050 // these come from ThreadPool 051 private RangeStatisticImpl openConnectionCount; 052 053 private CountStatisticImpl busyThreadCount; 054 055 // TODO - change the name to BoundedRangeStatisticsImpl 056 private BoundedRangeStatisticImpl busyThreads; 057 // TODO - spareThreads metrics = current - busy, maxSpareThreads, minSpareThreads 058 059 public TomcatWebConnectorStatsImpl() { 060 requestTime = new TimeStatisticImpl("Request Time", StatisticImpl.UNIT_TIME_MILLISECOND, 061 "The time to process all requests"); 062 activeRequestCount = new CountStatisticImpl("Active Request Count", StatisticImpl.UNIT_COUNT, 063 "currently active requests ", 0); 064 errorCount = new CountStatisticImpl("Error Count", StatisticImpl.UNIT_COUNT, 065 "The numbet of Errors during the observed period", 0); 066 bytesSentCount = new CountStatisticImpl("Bytes Sent", StatisticImpl.UNIT_COUNT, 067 "The number of bytes sent during the observerd period", 0); 068 bytesReceivedCount = new CountStatisticImpl("Bytes Received", StatisticImpl.UNIT_COUNT, 069 "The number of bytes received during the observerd period", 0); 070 openConnectionCount = new RangeStatisticImpl("" + "Open Connections", StatisticImpl.UNIT_COUNT, 071 "Range for connections opened during the observed period", 0); // all 0's 072 busyThreads = new BoundedRangeStatisticImpl("Busy Threads", StatisticImpl.UNIT_COUNT, 073 "BoundedRange for Threads currently busy serving requests", 0, 0, 0); 074 addStat("RequestTime", requestTime); // better name 075 addStat("activeRequestCount", activeRequestCount); 076 addStat("errorCount", errorCount); 077 addStat("bytesSent", bytesSentCount); 078 addStat("bytesReceived", bytesReceivedCount); 079 addStat("openConnectionCount", openConnectionCount); 080 addStat("busyThreads", busyThreads); 081 } 082 083 public RangeStatistic getActiveRequestCount() { 084 // TODO 085 return null; 086 } 087 088 public TimeStatistic getRequestTime() { 089 return requestTime; 090 } 091 092 public CountStatistic getErrorCount() { 093 return errorCount; 094 } 095 096 public CountStatistic getBytesSentCount() { 097 return bytesSentCount; 098 } 099 100 public CountStatistic getBytesReceivedCount() { 101 return bytesReceivedCount; 102 } 103 104 public RangeStatistic getOpenConnectionCount() { 105 return openConnectionCount; 106 } 107 108 // TODO - Move this to container statistics 109 public RangeStatistic getSpareThreadCount() { 110 return null; 111 } 112 113 /** 114 * These setters are used by native implementation 115 */ 116 public void setBytesReceivedCount(long bytesReceived) { 117 this.bytesReceivedCount.setCount(bytesReceived); 118 } 119 120 public void setBytesSentCount(long bytesSent) { 121 this.bytesSentCount.setCount(bytesSent); 122 } 123 124 public void setActiveRequestCount(int activeRequestCount) { 125 this.activeRequestCount.setCount(activeRequestCount); 126 } 127 128 public void setErrorCount(int errorCount) { 129 this.errorCount.setCount(errorCount); 130 } 131 132 public void setRequestTime(int count, long minTime, long maxTime, long totalTime) { 133 this.requestTime.setCount(count); 134 this.requestTime.setMinTime(minTime); 135 this.requestTime.setMaxTime(maxTime); 136 this.requestTime.setTotalTime(totalTime); 137 } 138 139 public void setOpenConnection(long current, long highMark, long lowMark) { 140 openConnectionCount.setCurrent(current); 141 openConnectionCount.setHighWaterMark(highMark); 142 openConnectionCount.setLowWaterMark(lowMark); 143 } 144 145 public void setBusyThreads(long current, long highWaterMark, long lowWaterMark, 146 long upperBound, long lowerBound) { 147 busyThreads.setCurrent(current); 148 busyThreads.setHighWaterMark(highWaterMark); 149 busyThreads.setLowWaterMark(lowWaterMark); //0? 150 busyThreads.setLowerBound(lowerBound); //0? 151 busyThreads.setUpperBound(upperBound); // always maxThreads 152 } 153 154 /** 155 * Used to access the native implementation in order to call setters 156 * TODO implement these if needed by console 157 */ 158 public RangeStatisticImpl getActiveRequestCountImpl() { 159 return null; 160 } 161 162 public TimeStatisticImpl getRequestDurationImpl() { 163 return null; 164 } 165 166 public CountStatisticImpl getTotalErrorCountImpl() { 167 return null; 168 } 169 170 public CountStatistic getTotalRequestCountImpl() { 171 return null; 172 } 173 174 }