@Counter public void process(CounterBasket pw) { if (CounterConstants.TOMCAT.equals(ObjTypeDetector.objType) == false) { return; } getMBeanServer(); if ((collectCnt <= 40 && collectCnt % 5 == 0) || ObjTypeDetector.dirtyConfig) { if (ObjTypeDetector.dirtyConfig) { AgentHeartBeat.clearSubObjects(); ObjTypeDetector.dirtyConfig = false; } getContextList(); } collectCnt++; for (CtxObj ctx : ctxList) { if (ctx.valueType == ValueEnum.DECIMAL) { try { MeterKey key = new MeterKey(ctx.mbeanHash, ctx.counter); long v = CastUtil.clong(server.getAttribute(ctx.mbean, ctx.attrName)); if (deltas.contains(ctx.counter)) { v = getDelta(key, v); MeterResource meter = getMeter(key); meter.add(v); v = (long) meter.getSum(60); long sum = (long) meter.getSum(300) / 5; pw.getPack(ctx.objName, TimeTypeEnum.REALTIME).add(ctx.counter, new DecimalValue(v)); pw.getPack(ctx.objName, TimeTypeEnum.FIVE_MIN).add(ctx.counter, new DecimalValue(sum)); } else { MeterResource meter = getMeter(key); meter.add(v); double d = meter.getAvg(30); double avg = meter.getAvg(300); FloatValue value = new FloatValue((float) d); FloatValue avgValue = new FloatValue((float) avg); pw.getPack(ctx.objName, TimeTypeEnum.REALTIME).add(ctx.counter, value); pw.getPack(ctx.objName, TimeTypeEnum.FIVE_MIN).add(ctx.counter, avgValue); } } catch (Exception e) { errors.add(ctx.attrName); collectCnt = 0; Logger.println("A902", e); } } } // long cpu2 = SysJMX.getCurrentThreadCPU(); }
public static synchronized int getUsers() { long max_think_time = Configure.getInstance().max_think_time; int v = 0; long now = System.currentTimeMillis(); try { Enumeration<LongLongLinkedMap.ENTRY> en = users.entries(); while (en.hasMoreElements()) { LongLongLinkedMap.ENTRY e = en.nextElement(); if (now - e.getValue() > max_think_time) { users.remove(e.getKey()); } else { v++; } } } catch (Throwable t) { Logger.println("A114", "METER-USERS" + t.toString()); } return v; }
private void getContextList() { ctxList.clear(); Set<ObjectName> mbeans = server.queryNames(null, null); for (final ObjectName mbean : mbeans) { String type = mbean.getKeyProperty("type"); if (type == null) { continue; } if (StringUtil.isEmpty(version) && "Server".equals(type)) { // Server // Bean try { Object value = server.getAttribute(mbean, "serverInfo"); if (value != null) { version = value.toString().split("/")[1]; Logger.println("Tomcat version = " + version); } } catch (Exception e) { e.printStackTrace(); } } if ("GlobalRequestProcessor".equals(type)) { String port = mbean.getKeyProperty("name"); try { String objName = conf.getObjName() + "/" + checkObjName(port); String objType = getReqProcType(); AgentHeartBeat.addObject(objType, HashUtil.hash(objName), objName); add( objName, mbean, objType, ValueEnum.DECIMAL, "bytesReceived", CounterConstants.REQUESTPROCESS_BYTES_RECEIVED); add( objName, mbean, objType, ValueEnum.DECIMAL, "bytesSent", CounterConstants.REQUESTPROCESS_BYTES_SENT); add( objName, mbean, objType, ValueEnum.DECIMAL, "errorCount", CounterConstants.REQUESTPROCESS_ERROR_COUNT); add( objName, mbean, objType, ValueEnum.DECIMAL, "processingTime", CounterConstants.REQUESTPROCESS_PROCESSING_TIME); add( objName, mbean, objType, ValueEnum.DECIMAL, "requestCount", CounterConstants.REQUESTPROCESS_REQUEST_COUNT); } catch (Exception e) { } } else if ("DataSource".equals(type)) { // datasource String name = mbean.getKeyProperty("name"); if (StringUtil.isNotEmpty(name)) { try { String objName = conf.getObjName() + "/" + checkObjName(name); String objType = getDataSourceType(); AgentHeartBeat.addObject(objType, HashUtil.hash(objName), objName); add( objName, mbean, objType, ValueEnum.DECIMAL, "numActive", CounterConstants.DATASOURCE_CONN_ACTIVE); add( objName, mbean, objType, ValueEnum.DECIMAL, "numIdle", CounterConstants.DATASOURCE_CONN_IDLE); } catch (Exception e) { } } } } }