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 com.sun.appserv.management.j2ee.statistics.CountStatisticImpl; 31 import com.sun.appserv.management.j2ee.statistics.StringStatistic; 32 import com.sun.appserv.management.j2ee.statistics.StringStatisticImpl; 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.server.ApplicationServer; 38 import com.sun.enterprise.server.pluggable.LBFeatureFactory; 39 40 public final class LoadBalancerServerStatsImpl implements CustomStatsImpl { 41 42 45 public Statistic [] getStatistics() { 46 LoadBalancerStatsInterface lbstats = lbff.getLoadBalancerMonitoringStats(lbConfigName,lbName); 47 Statistic [] statArr1 = new Statistic [3]; 48 StringStatistic stat11 = new StringStatisticImpl("Health", "Instance Health", "NONE", 0, 0, ""); 49 CountStatistic stat21 = new CountStatisticImpl("NumberOfActiveRequests", "Number Of Active Requests", "NONE", 0, 0, 0); 50 CountStatistic stat31 = new CountStatisticImpl("NumberOfTotalRequests", "Number Of Total Requests", "NONE", 0, 0, 0); 51 statArr1[0]=stat11; 52 statArr1[1]=stat21; 53 statArr1[2]=stat31; 54 if(lbstats == null) 55 return statArr1; 56 ClusterStats [] cstats = lbstats.getClusterStats(); 57 for(ClusterStats cstat :cstats){ 58 for(InstanceStats istat : cstat.getInstanceStats()){ 59 if(!istat.getId().equals(instanceName)) 60 continue; 61 Statistic [] statArr = new Statistic [3]; 62 String health = istat.getHealth(); 63 long activeReq = Long.parseLong(istat.getNumActiveRequests()); 64 long totalReq = Long.parseLong(istat.getNumTotalRequests()); 65 long sampleTime = new Date ().getTime(); 66 StringStatistic stat1 = new StringStatisticImpl("Health", "Instance Health", "NONE", startTime, sampleTime, health); 67 CountStatistic stat2 = new CountStatisticImpl("NumberOfActiveRequests", "Number Of Active Requests", "NONE", startTime, sampleTime, activeReq); 68 CountStatistic stat3 = new CountStatisticImpl("NumberOfTotalRequests", "Number Of Total Requests", "NONE", startTime, sampleTime, totalReq); 69 statArr[0] = stat1; 70 statArr[1] = stat2; 71 statArr[2] = stat3; 72 return statArr; 73 } 74 } 75 return null; 76 } 77 78 81 public StringStatistic getHealth() { 82 Statistic [] statArr = getStatistics(); 83 return (StringStatistic)statArr[0]; 84 } 85 86 89 public CountStatistic getNumberOfActiveRequests() { 90 Statistic [] statArr = getStatistics(); 91 return (CountStatistic )statArr[1]; 92 } 93 94 97 public CountStatistic getNumberOfTotalRequests() { 98 Statistic [] statArr = getStatistics(); 99 return (CountStatistic )statArr[2]; 100 } 101 102 103 public LoadBalancerServerStatsImpl(String lbName,String lbConfigName,String clusterName,String instanceName) { 104 this.lbName=lbName; 105 this.clusterName=clusterName; 106 this.instanceName=instanceName; 107 this.lbConfigName=lbConfigName; 108 this.lbff = ApplicationServer.getServerContext().getPluggableFeatureFactory().getLBFeatureFactory(); 109 this.startTime=new Date ().getTime(); 110 } 111 112 public LoadBalancerServerStatsImpl() { 113 } 114 115 private String instanceName = null; 116 private String lbName = null; 117 private String lbConfigName = null; 118 private String clusterName = null; 119 private LBFeatureFactory lbff = null; 120 private long startTime = 0; 121 122 123 } 124 | Popular Tags |