예제 #1
0
 public MapPack fetch() {
   TcpProxy tcp = TcpProxy.getTcpProxy(serverId);
   Pack pack = null;
   try {
     MapPack param = new MapPack();
     ListValue objLv = param.newList("objHash");
     Map<Integer, AgentObject> agentMap = AgentModelThread.getInstance().getAgentObjectMap();
     for (AgentObject p : agentMap.values()) {
       if (p.getObjType().equals(objType)) {
         objLv.add(p.getObjHash());
       }
     }
     pack = tcp.getSingle(RequestCmd.REALTIME_SERVICE_GROUP, param);
   } catch (Throwable th) {
     th.printStackTrace();
   } finally {
     TcpProxy.putTcpProxy(tcp);
   }
   MapPack m = null;
   if (pack != null) {
     m = (MapPack) pack;
     long time = TimeUtil.getCurrentTime(serverId);
     m.put("time", time);
     fiveMinMap.put(time, m);
   }
   return m;
 }
  public void refresh() {
    TcpProxy tcp = TcpProxy.getTcpProxy(serverId);
    Value v = null;
    try {
      MapPack param = new MapPack();
      ListValue objHashLv =
          AgentModelThread.getInstance().getLiveObjHashLV(serverId, CounterConstants.MARIA_PLUGIN);
      if (objHashLv.size() > 0) {
        param.put("objHash", objHashLv);
        v = tcp.getSingleValue(RequestCmd.DB_REALTIME_ACTIVITY, param);
      }
    } catch (Exception e) {
      ConsoleProxy.errorSafe(e.toString());
    } finally {
      TcpProxy.putTcpProxy(tcp);
    }
    if (v == null) {
      ExUtil.exec(
          canvas,
          new Runnable() {
            public void run() {
              setTitleImage(Images.inactive);
              long now = TimeUtil.getCurrentTime(serverId);
              long stime = now - TIME_RANGE;
              xyGraph.primaryXAxis.setRange(stime, now + 1);
            }
          });
    } else {
      MapValue mv = (MapValue) v;
      final DecimalValue callValue = new DecimalValue(mv.getLong("call"));
      final DecimalValue selectValue = new DecimalValue(mv.getLong("select"));
      final DecimalValue insertValue = new DecimalValue(mv.getLong("insert"));
      final DecimalValue updateValue = new DecimalValue(mv.getLong("update"));
      final DecimalValue deleteValue = new DecimalValue(mv.getLong("delete"));

      ExUtil.exec(
          canvas,
          new Runnable() {
            public void run() {
              setTitleImage(Images.active);
              long now = TimeUtil.getCurrentTime(serverId) / REFRESH_INTERVAL * REFRESH_INTERVAL;
              long stime = now - TIME_RANGE;
              xyGraph.primaryXAxis.setRange(stime, now + 1);
              ValueLog valueLog = new ValueLog();
              valueLog.time = now;
              valueLog.delete = deleteValue.value;
              valueLog.update = updateValue.value;
              valueLog.insert = insertValue.value;
              valueLog.select = selectValue.value;
              valueLog.call = callValue.value;
              valueLogs.add(valueLog);
              if (valueLogs.size() > BUFFER_SIZE) {
                valueLogs.removeFirst();
              }
              if (isStackView) {
                updateValue.value += deleteValue.value;
                insertValue.value += updateValue.value;
                selectValue.value += insertValue.value;
                callValue.value += selectValue.value;
              }
              ((CircularBufferDataProvider) callTrace.getDataProvider())
                  .addSample(new Sample(now, callValue.value));
              ((CircularBufferDataProvider) selectTrace.getDataProvider())
                  .addSample(new Sample(now, selectValue.value));
              ((CircularBufferDataProvider) insertTrace.getDataProvider())
                  .addSample(new Sample(now, insertValue.value));
              ((CircularBufferDataProvider) updateTrace.getDataProvider())
                  .addSample(new Sample(now, updateValue.value));
              ((CircularBufferDataProvider) deleteTrace.getDataProvider())
                  .addSample(new Sample(now, deleteValue.value));
              xyGraph.primaryYAxis.setRange(0, getMaxYValue());
            }

            private double getMaxYValue() {
              if (isStackView) {
                return ChartUtil.getMax(
                    ((CircularBufferDataProvider) callTrace.getDataProvider()).iterator());
              }
              double value =
                  ChartUtil.getMax(
                      ((CircularBufferDataProvider) callTrace.getDataProvider()).iterator());
              value =
                  Math.max(
                      value,
                      ChartUtil.getMax(
                          ((CircularBufferDataProvider) selectTrace.getDataProvider()).iterator()));
              value =
                  Math.max(
                      value,
                      ChartUtil.getMax(
                          ((CircularBufferDataProvider) insertTrace.getDataProvider()).iterator()));
              value =
                  Math.max(
                      value,
                      ChartUtil.getMax(
                          ((CircularBufferDataProvider) updateTrace.getDataProvider()).iterator()));
              value =
                  Math.max(
                      value,
                      ChartUtil.getMax(
                          ((CircularBufferDataProvider) deleteTrace.getDataProvider()).iterator()));
              return value;
            }
          });
    }
  }