public PerfCounterPack getPack(String objName, byte timeType) { Key key = new Key(objName, timeType); PerfCounterPack p = table.get(key); if (p == null) { p = new PerfCounterPack(); p.objName = objName; p.timetype = timeType; table.put(key, p); } return p; }
private void updateBatchService(){ PerfCounterPack pack = cb.getPack(conf.getObjName(), TimeTypeEnum.REALTIME); UdpLocalServer localServer = UdpLocalServer.getInstance(); pack.put(CounterConstants.BATCH_SERVICE, new DecimalValue(Main.batchMap.size())); pack.put(CounterConstants.BATCH_START, new DecimalValue(localServer.getStartBatchs())); pack.put(CounterConstants.BATCH_END, new DecimalValue(localServer.getEndBatchs())); pack.put(CounterConstants.BATCH_ENDNOSIGNAL, new DecimalValue(localServer.getEndNoSignalBatchs())); }
long sum = (long) meter.getSum(300) / 5; pw.getPack(beanObj.objName, TimeTypeEnum.REALTIME).add(beanObj.counter, new DecimalValue(v)); pw.getPack(beanObj.objName, TimeTypeEnum.FIVE_MIN).add(beanObj.counter, new DecimalValue(sum)); } else { MeterResource meter = getMeter(key); double avg = meter.getAvg(300); FloatValue avgValue = new FloatValue((float) avg); pw.getPack(beanObj.objName, TimeTypeEnum.REALTIME).add(beanObj.counter, new DecimalValue(v)); pw.getPack(beanObj.objName, TimeTypeEnum.FIVE_MIN).add(beanObj.counter, avgValue);
public PerfCounterPack getPack(String objName, byte timeType) { Key key = new Key(objName, timeType); PerfCounterPack p = table.get(key); if (p == null) { p = new PerfCounterPack(); p.objName = objName; p.timetype = timeType; table.put(key, p); } return p; }
public void process(CounterBasket pw) throws IOException { Configure conf = Configure.getInstance(); boolean redisEnabled = conf.getBoolean("redis_enabled", false); if (redisEnabled) { String serverIp = conf.getValue("redis_server_ip", "127.0.0.1"); int serverPort = conf.getInt("redis_server_port", 6379); String perfInfo = getRedisPerfInfo(serverIp, serverPort); String[] lines = perfInfo.split("\n"); PerfCounterPack p = pw.getPack(conf.getObjName(), TimeTypeEnum.REALTIME); for (String line : lines) { String key = line.substring(0, line.indexOf(':')); String value = line.substring(line.indexOf(':') + 1); if (floatSet.contains(key)) { p.put(key, new FloatValue(Float.valueOf(value.trim()))); } if (decimalSet.contains(key)) { p.put(key, new DecimalValue(Long.valueOf(value.trim()))); } } } }
long sum = (long) meter.getSum(300) / 5; pw.getPack(beanObj.objName, TimeTypeEnum.REALTIME).add(beanObj.counter, new DecimalValue(v)); pw.getPack(beanObj.objName, TimeTypeEnum.FIVE_MIN).add(beanObj.counter, new DecimalValue(sum)); } else { MeterResource meter = getMeter(key); double avg = meter.getAvg(300); FloatValue avgValue = new FloatValue((float) avg); pw.getPack(beanObj.objName, TimeTypeEnum.REALTIME).add(beanObj.counter, new DecimalValue(v)); pw.getPack(beanObj.objName, TimeTypeEnum.FIVE_MIN).add(beanObj.counter, avgValue);
public PerfCounterPack getPack(String objName, byte timeType) { Key key = new Key(objName, timeType); PerfCounterPack p = table.get(key); if (p == null) { p = new PerfCounterPack(); p.objName = objName; p.timetype = timeType; table.put(key, p); } return p; }
@Counter public void getHeapUsage(CounterBasket pw) { long total = Runtime.getRuntime().totalMemory(); long free = Runtime.getRuntime().freeMemory(); float tatalMb = (float) (total / 1024. / 1024.); float usedMb = (float) ((total - free) / 1024. / 1024.); heapmin.add(total - free); float used5MinAvgMb = (float) (heapmin.getAvg(300) / 1024. / 1024.); ListValue heapValues = new ListValue(); heapValues.add(tatalMb); heapValues.add(usedMb); PerfCounterPack p = pw.getPack(TimeTypeEnum.REALTIME); p.put(CounterConstants.JAVA_HEAP_TOT_USAGE, heapValues); p.put(CounterConstants.JAVA_HEAP_USED, new FloatValue(usedMb)); p.put(CounterConstants.JAVA_HEAP_TOTAL, new FloatValue(tatalMb)); p = pw.getPack(TimeTypeEnum.FIVE_MIN); p.put(CounterConstants.JAVA_HEAP_USED, new FloatValue(used5MinAvgMb)); p.put(CounterConstants.JAVA_HEAP_TOTAL, new FloatValue(tatalMb)); } }
v = (long) meter.getSum(60); long sum = (long) meter.getSum(300) / 5; pw.getPack(beanObj.objName, TimeTypeEnum.REALTIME).add(beanObj.counter, new DecimalValue(v)); pw.getPack(beanObj.objName, TimeTypeEnum.FIVE_MIN).add(beanObj.counter, new DecimalValue(sum)); } else { MeterResource meter = getMeter(key); double avg = meter.getAvg(300); FloatValue avgValue = new FloatValue((float) avg); pw.getPack(beanObj.objName, TimeTypeEnum.REALTIME).add(beanObj.counter, new DecimalValue(v)); pw.getPack(beanObj.objName, TimeTypeEnum.FIVE_MIN).add(beanObj.counter, avgValue);
private static PerfCounterPack extractPerfCounterPack(JSONArray perfJson, String objName) { PerfCounterPack perfPack = new PerfCounterPack(); perfPack.time = System.currentTimeMillis(); perfPack.timetype = TimeTypeEnum.REALTIME; perfPack.objName = objName; for (int i = 0; i < perfJson.size(); i++) { JSONObject perf = (JSONObject) perfJson.get(i); String name = (String) perf.get("name"); Number value = (Number) perf.get("value"); perfPack.data.put(name, new FloatValue(value.floatValue())); } return perfPack; }
@Counter public void getHeapUsage(CounterBasket pw) { long total = Runtime.getRuntime().totalMemory(); long free = Runtime.getRuntime().freeMemory(); float tatalMb = (float) (total / 1024. / 1024.); float usedMb = (float) ((total - free) / 1024. / 1024.); heapmin.add(total - free); float used5MinAvgMb = (float) (heapmin.getAvg(300) / 1024. / 1024.); ListValue heapValues = new ListValue(); heapValues.add(tatalMb); heapValues.add(usedMb); PerfCounterPack p = pw.getPack(TimeTypeEnum.REALTIME); p.put(CounterConstants.JAVA_HEAP_TOT_USAGE, heapValues); p.put(CounterConstants.JAVA_HEAP_USED, new FloatValue(usedMb)); p.put(CounterConstants.JAVA_HEAP_TOTAL, new FloatValue(tatalMb)); p = pw.getPack(TimeTypeEnum.FIVE_MIN); p.put(CounterConstants.JAVA_HEAP_USED, new FloatValue(used5MinAvgMb)); p.put(CounterConstants.JAVA_HEAP_TOTAL, new FloatValue(tatalMb)); } }
v = (long) meter.getSum(60); long sum = (long) meter.getSum(300) / 5; pw.getPack(beanObj.objName, TimeTypeEnum.REALTIME).add(beanObj.counter, new DecimalValue(v)); pw.getPack(beanObj.objName, TimeTypeEnum.FIVE_MIN).add(beanObj.counter, new DecimalValue(sum)); } else { MeterResource meter = getMeter(key); double avg = meter.getAvg(300); FloatValue avgValue = new FloatValue((float) avg); pw.getPack(beanObj.objName, TimeTypeEnum.REALTIME).add(beanObj.counter, new DecimalValue(v)); pw.getPack(beanObj.objName, TimeTypeEnum.FIVE_MIN).add(beanObj.counter, avgValue);
public static Pack createNonExt(byte packType) { switch (packType) { case MAP: return new MapPack(); case PERF_COUNTER: return new PerfCounterPack(); case PERF_STATUS: return new StatusPack(); case XLOG_PROFILE: return new XLogProfilePack(); case XLOG: return new XLogPack(); case TEXT: return new TextPack(); case ALERT: return new AlertPack(); case OBJECT: return new ObjectPack(); case STACK: return new StackPack(); case SUMMARY: return new SummaryPack(); case BATCH: return new BatchPack(); case PERF_INTERACTION_COUNTER: return new InteractionPerfCounterPack(); default: return null; } }
@Counter public void recentUser(CounterBasket pw) { int users =MeterUsers.getUsers(); PerfCounterPack p = pw.getPack(TimeTypeEnum.REALTIME); p.put(CounterConstants.WAS_RECENT_USER, new DecimalValue(users)); p = pw.getPack(TimeTypeEnum.FIVE_MIN); p.put(CounterConstants.WAS_RECENT_USER, new DecimalValue(users)); } }
long sum = (long) meter.getSum(300) / 5; pw.getPack(beanObj.objName, TimeTypeEnum.REALTIME).add(beanObj.counter, new DecimalValue(v)); pw.getPack(beanObj.objName, TimeTypeEnum.FIVE_MIN).add(beanObj.counter, new DecimalValue(sum)); } else { MeterResource meter = getMeter(key); double avg = meter.getAvg(300); FloatValue avgValue = new FloatValue((float) avg); pw.getPack(beanObj.objName, TimeTypeEnum.REALTIME).add(beanObj.counter, new DecimalValue(v)); pw.getPack(beanObj.objName, TimeTypeEnum.FIVE_MIN).add(beanObj.counter, avgValue);
return new MapPack(); case PERF_COUNTER: return new PerfCounterPack(); case PERF_STATUS: return new StatusPack();
@Counter public void recentUser(CounterBasket pw) { int users =MeterUsers.getUsers(); PerfCounterPack p = pw.getPack(TimeTypeEnum.REALTIME); p.put(CounterConstants.WAS_RECENT_USER, new DecimalValue(users)); p = pw.getPack(TimeTypeEnum.FIVE_MIN); p.put(CounterConstants.WAS_RECENT_USER, new DecimalValue(users)); } }
v = (long) meter.getSum(60); long sum = (long) meter.getSum(300) / 5; pw.getPack(beanObj.objName, TimeTypeEnum.REALTIME).add(beanObj.counter, new DecimalValue(v)); pw.getPack(beanObj.objName, TimeTypeEnum.FIVE_MIN).add(beanObj.counter, new DecimalValue(sum)); } else { MeterResource meter = getMeter(key); double avg = meter.getAvg(300); FloatValue avgValue = new FloatValue((float) avg); pw.getPack(beanObj.objName, TimeTypeEnum.REALTIME).add(beanObj.counter, new DecimalValue(v)); pw.getPack(beanObj.objName, TimeTypeEnum.FIVE_MIN).add(beanObj.counter, avgValue);
return new MapPack(); case PERF_COUNTER: return new PerfCounterPack(); case PERF_STATUS: return new StatusPack();
pcp.put(CounterConstants.WAS_TPS, new DecimalValue(5)); pcp.put(CounterConstants.WAS_ACTIVE_SPEED, new DecimalValue(5)); pcp.put(CounterConstants.WAS_ELAPSED_TIME, new DecimalValue(5)); pcp.put(CounterConstants.WAS_ELAPSED_90PCT, new DecimalValue(5)); pcp.put(CounterConstants.WAS_SERVICE_COUNT, new DecimalValue(5)); pcp.put(CounterConstants.WAS_ERROR_RATE, new DecimalValue(5)); pcp.put(CounterConstants.WAS_RECENT_USER, new DecimalValue(5)); pcp.put(CounterConstants.WAS_ACTIVE_SERVICE, new DecimalValue(5)); pcp.put(CounterConstants.JAVA_GC_COUNT, new DecimalValue(5)); pcp.put(CounterConstants.JAVA_GC_TIME, new DecimalValue(5)); pcp.put(CounterConstants.JAVA_HEAP_USED, new DecimalValue(5)); pcp.put(CounterConstants.JAVA_PERM_USED, new DecimalValue(5)); pcp.put(CounterConstants.JAVA_PROCESS_CPU, new DecimalValue(5)); int act1 = (int) (Math.random() * 10); int act2 = (int) (Math.random() * 10); activeSpeed.add(act2); activeSpeed.add(act3); pcp.put(CounterConstants.WAS_ACTIVE_SPEED, activeSpeed); pcp.put(CounterConstants.WAS_ACTIVE_SERVICE, new DecimalValue(active)); PerfCounterPack fiveminPcp = basket.getPack(objName, TimeTypeEnum.FIVE_MIN); fiveminPcp.put(CounterConstants.WAS_TPS, new DecimalValue(5)); fiveminPcp.put(CounterConstants.WAS_ACTIVE_SPEED, new DecimalValue(5)); fiveminPcp.put(CounterConstants.WAS_ELAPSED_TIME, new DecimalValue(5)); fiveminPcp.put(CounterConstants.WAS_ELAPSED_90PCT, new DecimalValue(5)); fiveminPcp.put(CounterConstants.WAS_SERVICE_COUNT, new DecimalValue(5)); fiveminPcp.put(CounterConstants.WAS_ERROR_RATE, new DecimalValue(5)); fiveminPcp.put(CounterConstants.WAS_RECENT_USER, new DecimalValue(5)); fiveminPcp.put(CounterConstants.WAS_ACTIVE_SERVICE, new DecimalValue(5));