예제 #1
0
 public void init(IViewSite site) throws PartInitException {
   super.init(site);
   String secId = site.getSecondaryId();
   String[] ids = StringUtil.split(secId, "&");
   this.serverId = CastUtil.cint(ids[0]);
   this.objType = ids[1];
   this.counter = ids[2];
   this.mode = CounterUtil.getTotalMode(objType, counter);
 }
  public void setInput(String sDate, String eDate, String objType, String counter, int serverId)
      throws Exception {
    this.sDate = sDate;
    this.eDate = eDate;
    this.objType = objType;
    this.counter = counter;
    this.mode = CounterUtil.getTotalMode(objType, counter);
    this.serverId = serverId;
    setViewTab(objType, counter, serverId, false);

    Server server = ServerManager.getInstance().getServer(serverId);
    String counterUnit = "";
    String counterDisplay = "";
    if (server != null) {
      counterUnit = server.getCounterEngine().getCounterUnit(objType, counter);
      counterDisplay = server.getCounterEngine().getCounterDisplayName(objType, counter);
      desc =
          "(Period) ["
              + sDate.substring(0, 4)
              + "-"
              + sDate.substring(4, 6)
              + "-"
              + sDate.substring(6, 8)
              + " ~ "
              + eDate.substring(0, 4)
              + "-"
              + eDate.substring(4, 6)
              + "-"
              + eDate.substring(6, 8)
              + "] Total "
              + counterDisplay;
    }
    serverText.setText(
        "ⓢ"
            + ((server == null) ? "?" : server.getName())
            + " |"
            + (!"".equals(counterUnit) ? " (" + counterUnit + ")" : ""));

    stime = DateUtil.getTime(sDate, "yyyyMMdd");
    etime = DateUtil.getTime(eDate, "yyyyMMdd") + DateUtil.MILLIS_PER_DAY;
    this.xyGraph.primaryXAxis.setRange(stime, etime);

    sDateText.setText(DateUtil.format(stime, "yyyy-MM-dd"));
    eDateText.setText(DateUtil.format(etime - 1, "yyyy-MM-dd"));

    buffer = (int) ((etime - stime) / DateUtil.MILLIS_PER_FIVE_MINUTE);
    traceDataProvider.setBufferSize(buffer);

    ExUtil.asyncRun(
        new Runnable() {
          public void run() {
            load();
          }
        });
  }
  public void createPartControl(Composite parent) {
    String displayCounter =
        defaultServer.getCounterEngine().getCounterDisplayName(objType, counter);
    String objectDisplay = defaultServer.getCounterEngine().getDisplayNameObjectType(objType);
    setPartName(grpName + " - " + displayCounter);
    mode = CounterUtil.getTotalMode(objType, counter);
    desc = grpName + " | (Today) [" + objectDisplay + "] " + displayCounter;
    GridLayout layout = new GridLayout(1, true);
    layout.marginHeight = 5;
    layout.marginWidth = 5;
    parent.setLayout(layout);
    parent.setBackground(ColorUtil.getInstance().getColor(SWT.COLOR_WHITE));
    parent.setBackgroundMode(SWT.INHERIT_FORCE);
    canvas = new FigureCanvas(parent);
    canvas.setScrollBarVisibility(FigureCanvas.NEVER);
    canvas.setLayoutData(new GridData(GridData.FILL_BOTH));
    canvas.addControlListener(
        new ControlListener() {
          boolean lock = false;

          public void controlResized(ControlEvent e) {
            org.eclipse.swt.graphics.Rectangle r = canvas.getClientArea();
            if (!lock) {
              lock = true;
              if (ChartUtil.isShowDescriptionAllowSize(r.height)) {
                CounterTodayGroupCountView.this.setContentDescription(desc);
              } else {
                CounterTodayGroupCountView.this.setContentDescription("");
              }
              r = canvas.getClientArea();
              lock = false;
            }
            if (xyGraph == null) return;
            xyGraph.setSize(r.width, r.height);
            lineWidth = r.width / 30;
            trace.setLineWidth(lineWidth);
            xAxisUnitWidth =
                xyGraph.primaryXAxis.getValuePosition(1, false)
                    - xyGraph.primaryXAxis.getValuePosition(0, false);
          }

          public void controlMoved(ControlEvent e) {}
        });

    canvas.addMouseListener(
        new MouseListener() {
          public void mouseUp(MouseEvent e) {
            writedValueMode = false;
            canvas.redraw();
          }

          public void mouseDown(MouseEvent e) {
            writeValue(e.x);
          }

          public void mouseDoubleClick(MouseEvent e) {}
        });

    xyGraph = new XYGraph();
    xyGraph.setShowLegend(false);

    canvas.setContents(xyGraph);

    xyGraph.primaryXAxis.setDateEnabled(false);
    xyGraph.primaryXAxis.setShowMajorGrid(false);

    xyGraph.primaryYAxis.setAutoScale(true);
    xyGraph.primaryYAxis.setShowMajorGrid(true);

    xyGraph.primaryXAxis.setTitle("");
    xyGraph.primaryYAxis.setTitle("");

    traceDataProvider = new CircularBufferDataProvider(true);
    traceDataProvider.setBufferSize(24);
    traceDataProvider.setCurrentXDataArray(new double[] {});
    traceDataProvider.setCurrentYDataArray(new double[] {});

    this.xyGraph.primaryXAxis.setRange(0, 24);

    // create the trace
    trace = new Trace("TotalCount", xyGraph.primaryXAxis, xyGraph.primaryYAxis, traceDataProvider);

    // set trace property
    trace.setPointStyle(PointStyle.NONE);
    // trace.getXAxis().setFormatPattern("HH");
    trace.getYAxis().setFormatPattern("#,##0");

    trace.setLineWidth(15);
    trace.setTraceType(TraceType.BAR);
    trace.setAreaAlpha(200);
    trace.setTraceColor(ColorUtil.getInstance().TOTAL_CHART_COLOR);

    // add the trace to xyGraph
    xyGraph.addTrace(trace);

    thread = new RefreshThread(this, 5000);
    thread.start();
    thread.setName(
        this.toString()
            + " - "
            + "objType:"
            + objType
            + ", counter:"
            + counter
            + ", grpName:"
            + grpName);
  }
예제 #4
0
  public void refresh() {
    String date = DateUtil.yyyymmdd(TimeUtil.getCurrentTime(serverId) - DateUtil.MILLIS_PER_DAY);
    if (date.equals(yesterday) == false) {
      yesterday = date;
      getYesterdayData(date);
    }
    final ArrayList<Pack> packs = new ArrayList<Pack>();
    TcpProxy tcp = TcpProxy.getTcpProxy(serverId);
    try {
      MapPack param = new MapPack();
      param.put("objType", objType);
      param.put("counter", counter);
      param.put("mode", CounterUtil.getTotalMode(objType, counter));
      isActive = false;
      tcp.process(
          RequestCmd.COUNTER_TODAY_ALL,
          param,
          new INetReader() {
            public void process(DataInputX in) throws IOException {
              packs.add(in.readPack());
            }
          });
    } catch (Throwable t) {
      ConsoleProxy.errorSafe(t.toString());
    } finally {
      TcpProxy.putTcpProxy(tcp);
    }

    final Map<Long, Double> valueMap =
        ScouterUtil.getLoadTotalMap(counter, packs, mode, TimeTypeEnum.FIVE_MIN);
    if (valueMap.size() > 0) {
      isActive = true;
    }

    ExUtil.exec(
        this.canvas,
        new Runnable() {
          public void run() {
            if (isActive) {
              setActive();
            } else {
              setInactive();
            }
            String date = DateUtil.yyyymmdd(TimeUtil.getCurrentTime(serverId));
            try {
              long stime = DateUtil.getTime(date, "yyyyMMdd");
              long etime = stime + DateUtil.MILLIS_PER_DAY;
              xyGraph.primaryXAxis.setRange(stime, etime);
              traceDataProvider.clearTrace();
              Set<Long> timeSet = valueMap.keySet();
              for (long time : timeSet) {
                traceDataProvider.addSample(
                    new Sample(CastUtil.cdouble(time), CastUtil.cdouble(valueMap.get(time))));
              }
              if (CounterUtil.isPercentValue(objType, counter)) {
                xyGraph.primaryYAxis.setRange(0, 100);
              } else {
                double max = ChartUtil.getMax(traceDataProvider.iterator());
                max = Math.max(max, yesterdayMax);
                xyGraph.primaryYAxis.setRange(0, max);
              }
            } catch (Exception e) {
              e.printStackTrace();
            }
            canvas.redraw();
            xyGraph.repaint();
          }
        });
  }