1 23 package com.sun.enterprise.web.stats; 24 25 import java.util.Hashtable ; 26 import java.util.ArrayList ; 27 import java.util.logging.Logger ; 28 import java.util.logging.Level ; 29 import java.text.MessageFormat ; 30 import javax.management.ObjectName ; 31 import javax.management.MBeanServerFactory ; 32 import javax.management.MBeanServer ; 33 import javax.management.MalformedObjectNameException ; 34 import javax.management.MBeanException ; 35 import javax.management.AttributeNotFoundException ; 36 import javax.management.InstanceNotFoundException ; 37 import javax.management.ReflectionException ; 38 import javax.management.j2ee.statistics.CountStatistic ; 39 import javax.management.j2ee.statistics.Statistic ; 40 import com.sun.logging.LogDomains; 41 import com.sun.enterprise.admin.monitor.stats.HTTPListenerStats; 42 import com.sun.enterprise.admin.monitor.stats.MutableCountStatistic; 43 import com.sun.enterprise.admin.monitor.stats.MutableCountStatisticImpl; 44 import com.sun.enterprise.admin.monitor.stats.GenericStatsImpl; 45 import com.sun.enterprise.admin.monitor.stats.CountStatisticImpl; 46 47 48 56 public class HTTPListenerStatsImpl implements HTTPListenerStats { 57 58 private static Logger _logger = null; 59 60 private GenericStatsImpl baseStatsImpl; 61 62 private MBeanServer server; 63 private ObjectName tpName; private ObjectName grpName; private MutableCountStatistic bytesReceived; 66 private MutableCountStatistic bytesSent; 67 private MutableCountStatistic errorCount; 68 private MutableCountStatistic maxTime; 69 private MutableCountStatistic processingTime; 70 private MutableCountStatistic requestCount; 71 private MutableCountStatistic curThreadCount; 72 private MutableCountStatistic curThreadsBusy; 73 private MutableCountStatistic maxThreads; 74 private MutableCountStatistic maxSpareThreads; 75 private MutableCountStatistic minSpareThreads; 76 private MutableCountStatistic count2xx; 77 private MutableCountStatistic count3xx; 78 private MutableCountStatistic count4xx; 79 private MutableCountStatistic count5xx; 80 private MutableCountStatistic countOther; 81 private MutableCountStatistic count200; 82 private MutableCountStatistic count302; 83 private MutableCountStatistic count304; 84 private MutableCountStatistic count400; 85 private MutableCountStatistic count401; 86 private MutableCountStatistic count403; 87 private MutableCountStatistic count404; 88 private MutableCountStatistic count503; 89 private MutableCountStatistic countOpenConnections; 90 private MutableCountStatistic maxOpenConnections; 91 92 93 107 public HTTPListenerStatsImpl(String domain, int port) { 108 109 _logger = LogDomains.getLogger(LogDomains.WEB_LOGGER); 110 111 baseStatsImpl = new GenericStatsImpl( 112 com.sun.enterprise.admin.monitor.stats.HTTPListenerStats.class, 113 this); 114 115 ArrayList servers = MBeanServerFactory.findMBeanServer(null); 117 if(!servers.isEmpty()) 118 server = (MBeanServer )servers.get(0); 119 else 120 server = MBeanServerFactory.createMBeanServer(); 121 122 String objNameStr = domain + ":type=Selector,name=http" + port; 127 try { 128 tpName = new ObjectName (objNameStr); 129 } catch (Throwable t) { 130 String msg = _logger.getResourceBundle().getString( 131 "webcontainer.objectNameCreationError"); 132 msg = MessageFormat.format(msg, new Object [] { objNameStr }); 133 _logger.log(Level.SEVERE, msg, t); 134 } 135 136 objNameStr = domain + ":type=GlobalRequestProcessor" 137 + ",name=http" + port; 138 try { 139 grpName = new ObjectName (objNameStr); 140 } catch (Throwable t) { 141 String msg = _logger.getResourceBundle().getString( 142 "webcontainer.objectNameCreationError"); 143 msg = MessageFormat.format(msg, new Object [] { objNameStr }); 144 _logger.log(Level.SEVERE, msg, t); 145 } 146 147 initializeStatistics(); 149 } 150 151 public CountStatistic getBytesReceived() { 153 bytesReceived.setCount(getBytesReceivedLong()); 154 return (CountStatistic )bytesReceived.unmodifiableView(); 155 } 156 157 public CountStatistic getBytesSent() { 158 bytesSent.setCount(getBytesSentLong()); 159 return (CountStatistic )bytesSent.unmodifiableView(); 160 } 161 162 public CountStatistic getProcessingTime() { 163 Object countObj = StatsUtil.getStatistic(server, grpName, "processingTime"); 164 processingTime.setCount(StatsUtil.getLongValue(countObj)); 165 return (CountStatistic )processingTime.unmodifiableView(); 166 } 167 168 public CountStatistic getRequestCount() { 169 requestCount.setCount(getRequestCountLong()); 170 return (CountStatistic )requestCount.unmodifiableView(); 171 } 172 173 public CountStatistic getErrorCount() { 174 Object countObj = StatsUtil.getStatistic(server, grpName, "errorCount"); 175 errorCount.setCount(StatsUtil.getLongValue(countObj)); 176 return (CountStatistic )errorCount.unmodifiableView(); 177 } 178 179 public CountStatistic getMaxTime() { 180 Object countObj = StatsUtil.getStatistic(server, grpName, "maxTime"); 181 maxTime.setCount(StatsUtil.getLongValue(countObj)); 182 return (CountStatistic )maxTime.unmodifiableView(); 183 } 184 185 186 193 public CountStatistic getCount2xx() { 194 count2xx.setCount(getCount2xxLong()); 195 return (CountStatistic )count2xx.unmodifiableView(); 196 } 197 198 205 public CountStatistic getCount3xx() { 206 count3xx.setCount(getCount3xxLong()); 207 return (CountStatistic )count3xx.unmodifiableView(); 208 } 209 210 217 public CountStatistic getCount4xx() { 218 count4xx.setCount(getCount4xxLong()); 219 return (CountStatistic )count4xx.unmodifiableView(); 220 } 221 222 229 public CountStatistic getCount5xx() { 230 count5xx.setCount(getCount5xxLong()); 231 return (CountStatistic )count5xx.unmodifiableView(); 232 } 233 234 242 public CountStatistic getCountOther() { 243 countOther.setCount(getCountOtherLong()); 244 return (CountStatistic )countOther.unmodifiableView(); 245 } 246 247 254 public CountStatistic getCount200() { 255 count200.setCount(getCount200Long()); 256 return (CountStatistic )count200.unmodifiableView(); 257 } 258 259 266 public CountStatistic getCount302() { 267 count302.setCount(getCount302Long()); 268 return (CountStatistic )count302.unmodifiableView(); 269 } 270 271 278 public CountStatistic getCount304() { 279 count304.setCount(getCount304Long()); 280 return (CountStatistic )count304.unmodifiableView(); 281 } 282 283 290 public CountStatistic getCount400() { 291 count400.setCount(getCount400Long()); 292 return (CountStatistic )count400.unmodifiableView(); 293 } 294 295 302 public CountStatistic getCount401() { 303 count401.setCount(getCount401Long()); 304 return (CountStatistic )count401.unmodifiableView(); 305 } 306 307 314 public CountStatistic getCount403() { 315 count403.setCount(getCount403Long()); 316 return (CountStatistic )count403.unmodifiableView(); 317 } 318 319 326 public CountStatistic getCount404() { 327 count404.setCount(getCount404Long()); 328 return (CountStatistic )count404.unmodifiableView(); 329 } 330 331 338 public CountStatistic getCount503() { 339 count503.setCount(getCount503Long()); 340 return (CountStatistic )count503.unmodifiableView(); 341 } 342 343 349 public CountStatistic getCountOpenConnections() { 350 countOpenConnections.setCount(getCountOpenConnectionsLong()); 351 return (CountStatistic )countOpenConnections.unmodifiableView(); 352 } 353 354 361 public CountStatistic getMaxOpenConnections() { 362 maxOpenConnections.setCount(getMaxOpenConnectionsLong()); 363 return (CountStatistic )maxOpenConnections.unmodifiableView(); 364 } 365 366 368 public CountStatistic getCurrentThreadCount() { 369 Object countObj = StatsUtil.getStatistic(server, tpName, 370 "currentThreadCountStats"); 371 curThreadCount.setCount(StatsUtil.getLongValue(countObj)); 372 return (CountStatistic )curThreadCount.unmodifiableView(); 373 } 374 375 public CountStatistic getCurrentThreadsBusy() { 376 Object countObj = StatsUtil.getStatistic(server, tpName, 377 "currentThreadsBusyStats"); 378 curThreadsBusy.setCount(StatsUtil.getLongValue(countObj)); 379 return (CountStatistic )curThreadsBusy.unmodifiableView(); 380 } 381 382 public CountStatistic getMaxSpareThreads() { 383 Object countObj = StatsUtil.getStatistic(server, tpName, 384 "maxSpareThreadsStats"); 385 maxSpareThreads.setCount(StatsUtil.getLongValue(countObj)); 386 return (CountStatistic )maxSpareThreads.unmodifiableView(); 387 } 388 389 public CountStatistic getMaxThreads() { 390 Object countObj = StatsUtil.getStatistic(server, tpName, 391 "maxThreadsStats"); 392 maxThreads.setCount(StatsUtil.getLongValue(countObj)); 393 return (CountStatistic )maxThreads.unmodifiableView(); 394 } 395 396 public CountStatistic getMinSpareThreads() { 397 Object countObj = StatsUtil.getStatistic(server, tpName, 398 "minSpareThreadsStats"); 399 minSpareThreads.setCount(StatsUtil.getLongValue(countObj)); 400 return (CountStatistic )minSpareThreads.unmodifiableView(); 401 } 402 403 408 public Statistic [] getStatistics() { 409 return baseStatsImpl.getStatistics(); 410 } 411 412 416 public Statistic getStatistic(String str) { 417 return baseStatsImpl.getStatistic(str); 418 } 419 420 425 public String [] getStatisticNames() { 426 return baseStatsImpl.getStatisticNames(); 427 } 428 429 430 433 434 long getBytesReceivedLong() { 435 Object countObj = StatsUtil.getStatistic(server, grpName, 436 "bytesReceived"); 437 return StatsUtil.getLongValue(countObj); 438 } 439 440 long getBytesSentLong() { 441 Object countObj = StatsUtil.getStatistic(server, grpName, 442 "bytesSent"); 443 return StatsUtil.getLongValue(countObj); 444 } 445 446 long getRequestCountLong() { 447 Object countObj = StatsUtil.getStatistic(server, grpName, 448 "requestCount"); 449 return StatsUtil.getLongValue(countObj); 450 } 451 452 long getCountOpenConnectionsLong() { 453 Object countObj = StatsUtil.getStatistic(server, grpName, 454 "countOpenConnections"); 455 return StatsUtil.getLongValue(countObj); 456 } 457 458 long getMaxOpenConnectionsLong() { 459 Object countObj = StatsUtil.getStatistic(server, grpName, 460 "maxOpenConnections"); 461 return StatsUtil.getLongValue(countObj); 462 463 } 464 465 long getCount2xxLong() { 466 Object countObj = StatsUtil.getStatistic(server, grpName, 467 "count2xx"); 468 return StatsUtil.getLongValue(countObj); 469 470 } 471 472 long getCount3xxLong() { 473 Object countObj = StatsUtil.getStatistic(server, grpName, 474 "count3xx"); 475 return StatsUtil.getLongValue(countObj); 476 } 477 478 long getCount4xxLong() { 479 Object countObj = StatsUtil.getStatistic(server, grpName, 480 "count4xx"); 481 return StatsUtil.getLongValue(countObj); 482 } 483 484 long getCount5xxLong() { 485 Object countObj = StatsUtil.getStatistic(server, grpName, 486 "count5xx"); 487 return StatsUtil.getLongValue(countObj); 488 } 489 490 long getCountOtherLong() { 491 Object countObj = StatsUtil.getStatistic(server, grpName, 492 "countOther"); 493 return StatsUtil.getLongValue(countObj); 494 } 495 496 long getCount200Long() { 497 Object countObj = StatsUtil.getStatistic(server, grpName, 498 "count200"); 499 return StatsUtil.getLongValue(countObj); 500 } 501 502 long getCount302Long() { 503 Object countObj = StatsUtil.getStatistic(server, grpName, 504 "count302"); 505 return StatsUtil.getLongValue(countObj); 506 } 507 508 long getCount304Long() { 509 Object countObj = StatsUtil.getStatistic(server, grpName, 510 "count304"); 511 return StatsUtil.getLongValue(countObj); 512 } 513 514 long getCount400Long() { 515 Object countObj = StatsUtil.getStatistic(server, grpName, 516 "count400"); 517 return StatsUtil.getLongValue(countObj); 518 } 519 520 long getCount401Long() { 521 Object countObj = StatsUtil.getStatistic(server, grpName, 522 "count401"); 523 return StatsUtil.getLongValue(countObj); 524 } 525 526 long getCount403Long() { 527 Object countObj = StatsUtil.getStatistic(server, grpName, 528 "count403"); 529 return StatsUtil.getLongValue(countObj); 530 } 531 532 long getCount404Long() { 533 Object countObj = StatsUtil.getStatistic(server, grpName, 534 "count404"); 535 return StatsUtil.getLongValue(countObj); 536 } 537 538 long getCount503Long() { 539 Object countObj = StatsUtil.getStatistic(server, grpName, 540 "count503"); 541 return StatsUtil.getLongValue(countObj); 542 } 543 544 545 551 String getLastRequestURI() { 552 return (String ) StatsUtil.getStatistic(server, grpName, 553 "lastRequestURI"); 554 } 555 556 562 String getLastRequestMethod() { 563 return (String ) StatsUtil.getStatistic(server, grpName, 564 "lastRequestMethod"); 565 } 566 567 574 long getLastRequestCompletionTime() { 575 Object countObj = StatsUtil.getStatistic(server, grpName, 576 "lastRequestCompletionTime"); 577 return StatsUtil.getLongValue(countObj); 578 } 579 580 581 584 585 private void initializeStatistics() { 586 587 CountStatistic c = new CountStatisticImpl("BytesReceived"); 589 bytesReceived = new MutableCountStatisticImpl(c); 590 591 c = new CountStatisticImpl("BytesSent"); 593 bytesSent = new MutableCountStatisticImpl(c); 594 595 c = new CountStatisticImpl("ErrorCount"); 597 errorCount = new MutableCountStatisticImpl(c); 598 599 c = new CountStatisticImpl("MaxTime", "milliseconds"); 601 maxTime = new MutableCountStatisticImpl(c); 602 603 c = new CountStatisticImpl("ProcessingTime", "milliseconds"); 605 processingTime = new MutableCountStatisticImpl(c); 606 607 c = new CountStatisticImpl("RequestCount"); 609 requestCount = new MutableCountStatisticImpl(c); 610 611 c = new CountStatisticImpl("CurrentThreadCount"); 613 curThreadCount = new MutableCountStatisticImpl(c); 614 615 c = new CountStatisticImpl("CurrentThreadsBusy"); 617 curThreadsBusy = new MutableCountStatisticImpl(c); 618 619 c = new CountStatisticImpl("MaxThreads"); 621 maxThreads = new MutableCountStatisticImpl(c); 622 623 c = new CountStatisticImpl("MaxSpareThreads"); 625 maxSpareThreads = new MutableCountStatisticImpl(c); 626 627 c = new CountStatisticImpl("MinSpareThreads"); 629 minSpareThreads = new MutableCountStatisticImpl(c); 630 631 c = new CountStatisticImpl("Count2xx"); 633 count2xx = new MutableCountStatisticImpl(c); 634 635 c = new CountStatisticImpl("Count3xx"); 637 count3xx = new MutableCountStatisticImpl(c); 638 639 c = new CountStatisticImpl("Count4xx"); 641 count4xx = new MutableCountStatisticImpl(c); 642 643 c = new CountStatisticImpl("Count5xx"); 645 count5xx = new MutableCountStatisticImpl(c); 646 647 c = new CountStatisticImpl("CountOther"); 649 countOther = new MutableCountStatisticImpl(c); 650 651 c = new CountStatisticImpl("Count200"); 653 count200 = new MutableCountStatisticImpl(c); 654 655 c = new CountStatisticImpl("Count302"); 657 count302 = new MutableCountStatisticImpl(c); 658 659 c = new CountStatisticImpl("Count304"); 661 count304 = new MutableCountStatisticImpl(c); 662 663 c = new CountStatisticImpl("Count400"); 665 count400 = new MutableCountStatisticImpl(c); 666 667 c = new CountStatisticImpl("Count401"); 669 count401 = new MutableCountStatisticImpl(c); 670 671 c = new CountStatisticImpl("Count403"); 673 count403 = new MutableCountStatisticImpl(c); 674 675 c = new CountStatisticImpl("Count404"); 677 count404 = new MutableCountStatisticImpl(c); 678 679 c = new CountStatisticImpl("Count503"); 681 count503 = new MutableCountStatisticImpl(c); 682 683 c = new CountStatisticImpl("CountOpenConnections"); 685 countOpenConnections = new MutableCountStatisticImpl(c); 686 687 c = new CountStatisticImpl("MaxOpenConnections"); 689 maxOpenConnections = new MutableCountStatisticImpl(c); 690 } 691 692 } 693 | Popular Tags |