3333import scouter .agent .counter .CounterBasket ;
3434import scouter .agent .counter .anotation .Counter ;
3535import scouter .agent .counter .meter .MeterResource ;
36+ import scouter .agent .counter .task .TomcatJMXPerf .CtxObj ;
37+ import scouter .agent .counter .task .TomcatJMXPerf .MeterKey ;
3638import scouter .lang .TimeTypeEnum ;
3739import scouter .lang .conf .ConfObserver ;
3840import scouter .lang .counters .CounterConstants ;
@@ -78,22 +80,22 @@ private MeterResource getMeter(MeterKey key) {
7880
7981 static class MeterKey {
8082
81- String objName ;
83+ int mbeanHash ;
8284 String counter ;
8385
84- public MeterKey (String objName , String counter ) {
85- this .objName = objName ;
86+ public MeterKey (int mbeanHash , String counter ) {
87+ this .mbeanHash = mbeanHash ;
8688 this .counter = counter ;
8789 }
8890
8991 public int hashCode () {
90- return objName . hashCode () ^ counter .hashCode ();
92+ return mbeanHash ^ counter .hashCode ();
9193 }
9294
9395 public boolean equals (Object obj ) {
9496 if (obj instanceof MeterKey ) {
9597 MeterKey key = (MeterKey ) obj ;
96- return (this .objName . equals ( key .objName ) ) && (this .counter .equals (key .counter ));
98+ return (this .mbeanHash == key .mbeanHash ) && (this .counter .equals (key .counter ));
9799 }
98100 return false ;
99101 }
@@ -110,8 +112,6 @@ public void process(CounterBasket pw) {
110112 if (CounterConstants .JBOSS .equals (ObjTypeDetector .objType ) == false ) {
111113 return ;
112114 }
113- // if(CounterConstants.JBOSS.equals(conf.objType) ==false)
114- // return;
115115
116116 getMBeanServer ();
117117
@@ -124,12 +124,12 @@ public void process(CounterBasket pw) {
124124 }
125125 collectCnt ++;
126126
127+ collectCnt ++;
127128 MBeanServer server = servers .get (0 );
128-
129129 for (CtxObj ctx : ctxList ) {
130130 if (ctx .valueType == ValueEnum .DECIMAL ) {
131131 try {
132- MeterKey key = new MeterKey (ctx .objName , ctx .counter );
132+ MeterKey key = new MeterKey (ctx .mbeanHash , ctx .counter );
133133 long v = CastUtil .clong (server .getAttribute (ctx .mbean , ctx .attrName ));
134134 if (deltas .contains (ctx .counter )) {
135135 v = getDelta (key , v );
@@ -138,17 +138,17 @@ public void process(CounterBasket pw) {
138138 v = (long ) meter .getSum (60 );
139139 long sum = (long ) meter .getSum (300 ) / 5 ;
140140
141- pw .getPack (ctx .objName , TimeTypeEnum .REALTIME ).put (ctx .counter , new DecimalValue (v ));
142- pw .getPack (ctx .objName , TimeTypeEnum .FIVE_MIN ).put (ctx .counter , new DecimalValue (sum ));
141+ pw .getPack (ctx .objName , TimeTypeEnum .REALTIME ).add (ctx .counter , new DecimalValue (v ));
142+ pw .getPack (ctx .objName , TimeTypeEnum .FIVE_MIN ).add (ctx .counter , new DecimalValue (sum ));
143143 } else {
144144 MeterResource meter = getMeter (key );
145145 meter .add (v );
146146 double d = meter .getAvg (30 );
147147 double avg = meter .getAvg (300 );
148148 FloatValue value = new FloatValue ((float ) d );
149149 FloatValue avgValue = new FloatValue ((float ) avg );
150- pw .getPack (ctx .objName , TimeTypeEnum .REALTIME ).put (ctx .counter , value );
151- pw .getPack (ctx .objName , TimeTypeEnum .FIVE_MIN ).put (ctx .counter , avgValue );
150+ pw .getPack (ctx .objName , TimeTypeEnum .REALTIME ).add (ctx .counter , value );
151+ pw .getPack (ctx .objName , TimeTypeEnum .FIVE_MIN ).add (ctx .counter , avgValue );
152152 }
153153 } catch (Exception e ) {
154154 errors .add (ctx .attrName );
@@ -268,23 +268,30 @@ private static String checkObjName(String name) {
268268 }
269269
270270 class CtxObj {
271- private String objName ;
272- private ObjectName mbean ;
273- private String objType ;
274- private byte valueType ;
275- private String attrName ;
276- private String counter ;
271+ public int mbeanHash ;
272+ public String objName ;
273+ public ObjectName mbean ;
274+ public String objType ;
275+ public byte valueType ;
276+ public String attrName ;
277+ public String counter ;
277278
278279 public CtxObj (String objName , ObjectName mbean , String objType , byte valueType , String attrName , String counter ) {
279280
280281 this .objName = objName ;
281282 this .mbean = mbean ;
283+ this .mbeanHash = HashUtil .hash (mbean .toString ());
282284 this .objType = objType ;
283285 this .valueType = valueType ;
284286 this .attrName = attrName ;
285287 this .counter = counter ;
286288 }
287289
288- }
290+ @ Override
291+ public String toString () {
292+ return "CtxObj [objName=" + objName + ", mbean=" + mbean + ", objType=" + objType + ", valueType="
293+ + valueType + ", attrName=" + attrName + ", counter=" + counter + "]" ;
294+ }
289295
296+ }
290297}
0 commit comments