@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(); }
@Counter public void getHeapUsage(CounterBasket pw) { long total = Runtime.getRuntime().totalMemory(); long free = Runtime.getRuntime().freeMemory(); float used = (float) ((total - free) / 1024. / 1024.); heapmin.add(total - free); float usedmin = (float) (heapmin.getAvg(300) / 1024. / 1024.); ListValue heapValues = new ListValue(); heapValues.add((float) (total / 1024. / 1024.)); heapValues.add(used); PerfCounterPack p = pw.getPack(TimeTypeEnum.REALTIME); p.put(CounterConstants.JAVA_HEAP_TOT_USAGE, heapValues); p.put(CounterConstants.JAVA_HEAP_USED, new FloatValue(used)); p = pw.getPack(TimeTypeEnum.FIVE_MIN); p.put(CounterConstants.JAVA_HEAP_USED, new FloatValue(usedmin)); }