Ejemplo n.º 1
0
  private String fillCommonStats(Map<Tracked, RequestCounter> stats, Tracked t) {
    StringBuilder sb = new StringBuilder();
    int j = 0;

    if (j++ > 0) {
      sb.append(",\n");
    }

    sb.append("        \"");
    sb.append(t.toString());
    sb.append("\": { ");

    sb.append("\"total\": ");
    sb.append(stats.get(t).getTotalCount());
    sb.append(", ");

    sb.append("\"operations\": ");
    sb.append(stats.get(t).getCount());
    sb.append(", ");

    sb.append("\"throughput\": ");
    sb.append(stats.get(t).getDisplayThroughput());
    sb.append(", ");

    sb.append("\"avg_time_ms\": ");
    sb.append(stats.get(t).getDisplayAverageTimeInMs());
    sb.append(" }");

    return sb.toString();
  }
Ejemplo n.º 2
0
  @Override
  protected void doGet(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {

    String storeName = request.getParameter("store");

    String format = request.getParameter("format");
    if ("json".equals(format)) {
      outputJSON(response);
      return;
    } else {
      response.setContentType("text/html");

      long refreshTime = 600;
      String refresh = request.getParameter("refresh");
      if (refresh != null) {
        try {
          refreshTime = Integer.parseInt(refresh);
        } catch (NumberFormatException e) {
          response.sendError(HttpServletResponse.SC_BAD_REQUEST);
        }
      }

      List<Store<ByteArray, byte[], byte[]>> stores = null;
      if (storeName == null) {
        stores = server.getStoreRepository().getAllLocalStores();
      } else {
        stores = Collections.singletonList(server.getStoreRepository().getLocalStore(storeName));
      }

      Map<String, Object> params = Maps.newHashMap();
      params.put("status", abstractSocketService.getStatusManager());
      params.put("counters", Tracked.values());
      params.put("stores", stores);
      params.put("refresh", refreshTime);
      velocityEngine.render("status.vm", params, response.getOutputStream());
    }
  }
Ejemplo n.º 3
0
  protected void outputJSON(HttpServletResponse response) {
    StringBuilder sb = new StringBuilder("{\n");

    sb.append("  \"servertime\": \"");
    sb.append(new Date());
    sb.append("\",");

    sb.append("\n  \"server\": \"");
    sb.append(myMachine);
    sb.append("\",");

    sb.append("\n  \"node\": \"");
    sb.append(server.getMetadataStore().getNodeId());
    sb.append("\",");

    sb.append("\n  \"uptime\": \"");
    sb.append(abstractSocketService.getStatusManager().getFormattedUptime());
    sb.append("\",");

    sb.append("\n  \"num_workers\": ");
    sb.append(abstractSocketService.getStatusManager().getActiveWorkersCount());
    sb.append(",");

    sb.append("\n  \"pool_size\": ");
    sb.append(abstractSocketService.getStatusManager().getWorkerPoolSize());
    sb.append(",");

    sb.append("\n  \"stores\": {");

    int i = 0;
    for (Store<ByteArray, byte[], byte[]> store : server.getStoreRepository().getAllLocalStores()) {

      if (i++ > 0) {
        sb.append(",");
      }
      sb.append("\n    \"");
      sb.append(store.getName());
      sb.append("\" : {\n");

      if (store instanceof StatTrackingStore) {
        StatTrackingStore statStore = (StatTrackingStore) store;
        Map<Tracked, RequestCounter> stats = statStore.getStats().getCounters();
        for (Tracked t : Tracked.values()) {
          if (t == Tracked.EXCEPTION) {
            continue;
          }
          sb.append(fillCommonStats(stats, t));
        }
        sb.append(",\n        \"num_exceptions\": ");
        sb.append(statStore.getStats().getCount(Tracked.EXCEPTION));
        sb.append("\n");
        sb.append("    }");
      }

      if (store instanceof QuotaLimitingStore) {
        QuotaLimitingStore quotaStore = (QuotaLimitingStore) store;
        Map<Tracked, RequestCounter> stats = quotaStore.getStats().getCounters();
        for (Tracked t : Tracked.values()) {
          if (t == Tracked.EXCEPTION) {
            continue;
          }
          sb.append(fillCommonStats(stats, t));
        }
        sb.append(",\n        \"num_exceptions\": ");
        sb.append(quotaStore.getStats().getCount(Tracked.EXCEPTION));
        sb.append("\n");
        sb.append("    }");
      }
    }

    sb.append("\n  }\n");
    sb.append("}\n");

    try {
      response.setContentType("text/plain");
      OutputStreamWriter writer = new OutputStreamWriter(response.getOutputStream());
      writer.write(sb.toString());
      writer.flush();
    } catch (Exception e) {
      throw new VoldemortException(e);
    }
  }