1 23 24 package com.sun.enterprise.management.monitor.stats; 25 26 import java.util.Date ; 27 import java.util.Map ; 28 import javax.management.j2ee.statistics.Statistic ; 29 import javax.management.j2ee.statistics.CountStatistic ; 30 import javax.management.j2ee.statistics.TimeStatistic ; 31 import com.sun.appserv.management.j2ee.statistics.CountStatisticImpl; 32 import com.sun.appserv.management.j2ee.statistics.TimeStatisticImpl; 33 import com.sun.appserv.management.monitor.statistics.LoadBalancerServerStats; 34 import com.sun.enterprise.admin.monitor.stats.lb.ClusterStats; 35 import com.sun.enterprise.admin.monitor.stats.lb.InstanceStats; 36 import com.sun.enterprise.admin.monitor.stats.lb.LoadBalancerStatsInterface; 37 import com.sun.enterprise.admin.monitor.stats.lb.InstanceStatsInterface; 38 import com.sun.enterprise.server.ApplicationServer; 39 import com.sun.enterprise.server.pluggable.LBFeatureFactory; 40 41 42 public final class LoadBalancerContextRootStatsImpl implements CustomStatsImpl { 43 44 47 public Statistic [] getStatistics() { 48 LoadBalancerStatsInterface lbstats = 49 lbff.getLoadBalancerMonitoringStats(lbConfigName,lbName); 50 InstanceStatsInterface instance = getInstanceStats(lbstats); 51 return createStats(instance); 52 } 53 54 57 public TimeStatistic getResponseTime() { 58 LoadBalancerStatsInterface lbstats = 59 lbff.getLoadBalancerMonitoringStats(lbConfigName,lbName); 60 InstanceStatsInterface istat = getInstanceStats(lbstats); 61 if(istat!=null){ 62 long avgRespTime = Long.parseLong( 63 istat.getApplicationStatsAverageResponseTime()); 64 long maxRespTime = Long.parseLong( 65 istat.getApplicationStatsMaxResponseTime()); 66 long minRespTime = Long.parseLong( 67 istat.getApplicationStatsMinResponseTime()); 68 long totalRequests = Long.parseLong( 69 istat.getApplicationStatsNumTotalRequests()); 70 long sampleTime = System.currentTimeMillis(); 71 return createResponseTimeStat(maxRespTime, 72 totalRequests, sampleTime, 73 minRespTime, avgRespTime); 74 } 75 return null; 76 } 77 78 81 public CountStatistic getAverageResponseTime() { 82 LoadBalancerStatsInterface lbstats = 83 lbff.getLoadBalancerMonitoringStats(lbConfigName,lbName); 84 InstanceStatsInterface istat = getInstanceStats(lbstats); 85 if(istat!=null){ 86 long avgRespTime = Long.parseLong( 87 istat.getApplicationStatsAverageResponseTime()); 88 long sampleTime = System.currentTimeMillis(); 89 return createAverageRespTimeStat(sampleTime,avgRespTime); 90 } 91 return null; 92 } 93 94 97 public CountStatistic getFailoverReqCount() { 98 LoadBalancerStatsInterface lbstats = 99 lbff.getLoadBalancerMonitoringStats(lbConfigName,lbName); 100 InstanceStatsInterface istat = getInstanceStats(lbstats); 101 if(istat!=null){ 102 long time = Long.parseLong( 103 istat.getApplicationStatsNumFailoverRequests()); 104 long sampleTime = System.currentTimeMillis(); 105 return createFailoverReqCountStat(sampleTime,time); 106 } 107 return null; 108 } 109 110 113 public CountStatistic getErrorRequestCount() { 114 LoadBalancerStatsInterface lbstats = 115 lbff.getLoadBalancerMonitoringStats(lbConfigName,lbName); 116 InstanceStatsInterface istat = getInstanceStats(lbstats); 117 if(istat!=null){ 118 long time = Long.parseLong( 119 istat.getApplicationStatsNumErrorRequests()); 120 long sampleTime = System.currentTimeMillis(); 121 return createErrorRequestCountStat(sampleTime,time); 122 } 123 return null; 124 } 125 126 129 public CountStatistic getActiveRequestCount() { 130 LoadBalancerStatsInterface lbstats = 131 lbff.getLoadBalancerMonitoringStats(lbConfigName,lbName); 132 InstanceStatsInterface istat = getInstanceStats(lbstats); 133 if(istat!=null){ 134 long time = Long.parseLong( 135 istat.getApplicationStatsNumActiveRequests()); 136 long sampleTime = System.currentTimeMillis(); 137 return createActiveRequestCountStat(sampleTime,time); 138 } 139 return null; 140 } 141 142 145 public CountStatistic getTotalRequestCount() { 146 LoadBalancerStatsInterface lbstats = 147 lbff.getLoadBalancerMonitoringStats(lbConfigName,lbName); 148 InstanceStatsInterface istat = getInstanceStats(lbstats); 149 if(istat!=null){ 150 long time = Long.parseLong( 151 istat.getApplicationStatsNumTotalRequests()); 152 long sampleTime = System.currentTimeMillis(); 153 return createTotalRequestCountStat(sampleTime,time); 154 } 155 return null; 156 } 157 158 162 public CountStatistic getIdempotentUrlAccessCount() { 163 LoadBalancerStatsInterface lbstats = 164 lbff.getLoadBalancerMonitoringStats(lbConfigName,lbName); 165 InstanceStatsInterface istat = getInstanceStats(lbstats); 166 if(istat!=null){ 167 long time = Long.parseLong( 168 istat.getApplicationStatsNumIdempotentUrlRequests()); 169 long sampleTime = System.currentTimeMillis(); 170 return createIdempotentUrlAccessCountStat(sampleTime,time); 171 } 172 return null; 173 } 174 175 176 public LoadBalancerContextRootStatsImpl(String lbName,String lbConfigName, 177 String clusterName,String instanceName,String appName, 178 String contextRoot) { 179 this.lbName=lbName; 180 this.clusterName=clusterName; 181 this.instanceName=instanceName; 182 this.appName=appName; 183 this.contextRoot=contextRoot; 184 this.lbConfigName=lbConfigName; 185 this.lbff = ApplicationServer.getServerContext(). 186 getPluggableFeatureFactory().getLBFeatureFactory(); 187 this.startTime=System.currentTimeMillis(); 188 } 189 190 public LoadBalancerContextRootStatsImpl() { 191 } 192 193 private String contextRoot = null; 194 private String lbName = null; 195 private String lbConfigName = null; 196 private String clusterName = null; 197 private String instanceName = null; 198 private String appName = null; 199 private LBFeatureFactory lbff = null; 200 private long startTime = 0; 201 202 private InstanceStatsInterface getInstanceStats( 203 final LoadBalancerStatsInterface lbstats) { 204 if(lbstats == null) 205 return null; 206 ClusterStats [] cstats = lbstats.getClusterStats(); 207 for(ClusterStats cstat :cstats){ 208 for(InstanceStats istat : cstat.getInstanceStats()){ 209 if(!istat.getId().equals(instanceName)) 210 continue; 211 String appid = istat.getApplicationStatsId(); 212 if(!appid.equals(contextRoot)) 213 continue; 214 return istat; 215 216 } 217 } 218 return null; 219 } 220 221 private Statistic [] createStats(InstanceStatsInterface istat) { 222 Statistic [] emptyStats = createEmptyStats(); 223 if(istat==null) 224 return emptyStats; 225 long avgRespTime = Long.parseLong( 226 istat.getApplicationStatsAverageResponseTime()); 227 long maxRespTime = Long.parseLong( 228 istat.getApplicationStatsMaxResponseTime()); 229 long minRespTime = Long.parseLong( 230 istat.getApplicationStatsMinResponseTime()); 231 long noActiveReq = Long.parseLong( 232 istat.getApplicationStatsNumActiveRequests()); 233 long noErrorReq = Long.parseLong( 234 istat.getApplicationStatsNumErrorRequests()); 235 long noFailoverReq = Long.parseLong( 236 istat.getApplicationStatsNumFailoverRequests()); 237 long noIdempotentUrlReq = Long.parseLong( 238 istat.getApplicationStatsNumIdempotentUrlRequests()); 239 long totalRequests = Long.parseLong( 240 istat.getApplicationStatsNumTotalRequests()); 241 long sampleTime = System.currentTimeMillis(); 242 Statistic [] statArr = new Statistic [7]; 243 statArr[0] = createResponseTimeStat(maxRespTime, totalRequests, 244 sampleTime, minRespTime, avgRespTime); 245 statArr[1] = createAverageRespTimeStat(sampleTime, avgRespTime); 246 statArr[2] = createFailoverReqCountStat(sampleTime, noFailoverReq); 247 statArr[3] = createErrorRequestCountStat(sampleTime, noErrorReq); 248 statArr[4] = createActiveRequestCountStat(sampleTime, noActiveReq); 249 statArr[5] = createTotalRequestCountStat(sampleTime, totalRequests); 250 statArr[6] = createIdempotentUrlAccessCountStat(sampleTime, 251 noIdempotentUrlReq); 252 253 return statArr; 254 } 255 256 private CountStatistic createAverageRespTimeStat(final long sampleTime, 257 final long count) { 258 return new CountStatisticImpl("AverageResponseTime", 259 "Average Response Time", "MILLISECOND", startTime, sampleTime,count); 260 } 261 private CountStatistic createFailoverReqCountStat(final long sampleTime, 262 final long count) { 263 return new CountStatisticImpl("FailoverReqCount", 264 "Failover Request Count", "NONE", startTime, sampleTime,count); 265 } 266 private CountStatistic createErrorRequestCountStat(final long sampleTime, 267 final long count) { 268 return new CountStatisticImpl("ErrorRequestCount", 269 "Error Request Count", "NONE", startTime, sampleTime,count); 270 } 271 private CountStatistic createActiveRequestCountStat(final long sampleTime, 272 final long count) { 273 return new CountStatisticImpl("ActiveRequestCount", 274 "Active Request Count", "NONE", startTime, sampleTime,count); 275 } 276 private CountStatistic createTotalRequestCountStat(final long sampleTime, 277 final long count) { 278 return new CountStatisticImpl("TotalRequestCount", 279 "Total Request Count", "NONE", startTime, sampleTime,count); 280 } 281 private CountStatistic createIdempotentUrlAccessCountStat(final long sampleTime, 282 final long count) { 283 return new CountStatisticImpl("IdempotentUrlAccessCount", 284 "Idempotent Url Access Count", "NONE", startTime, sampleTime,count); 285 } 286 287 private TimeStatistic createResponseTimeStat(final long maxRespTime, 288 final long totalRequests, final long sampleTime, 289 final long minRespTime, final long avgRespTime) { 290 return new TimeStatisticImpl("ResponseTime", "Response Time", 291 "MILLISECOND", startTime, sampleTime,totalRequests,maxRespTime, 292 minRespTime, totalRequests*avgRespTime); 293 } 294 295 private Statistic [] createEmptyStats() { 296 Statistic [] statArr1 = new Statistic [7]; 297 statArr1[0] = createResponseTimeStat(-1, -1, -1, -1, -1); 298 statArr1[1] = createAverageRespTimeStat(-1, -1); 299 statArr1[2] = createFailoverReqCountStat(-1, -1); 300 statArr1[3] = createErrorRequestCountStat(-1, -1); 301 statArr1[4] = createActiveRequestCountStat(-1, -1); 302 statArr1[5] = createTotalRequestCountStat(-1, -1); 303 statArr1[6] = createIdempotentUrlAccessCountStat( -1, -1); 304 return statArr1; 305 } 306 307 308 } 309 | Popular Tags |