docs: public void execute(final TSDB tsdb, final HttpQuery query) {
      // only accept GET/POST
      if (query.method() != HttpMethod.GET && query.method() != HttpMethod.POST) {
        throw new BadRequestException(HttpResponseStatus.METHOD_NOT_ALLOWED, 
            "Method not allowed", "The HTTP method [" + query.method().getName() +
            "] is not permitted for this endpoint");
      }
      
      try {
        final String[] uri = query.explodeAPIPath();
        final String endpoint = uri.length > 1 ? uri[1].toLowerCase() : "";
  
        // Handle /threads and /regions.
        if ("threads".equals(endpoint)) {
          printThreadStats(query);
          return;
        } else if ("jvm".equals(endpoint)) {
          printJVMStats(tsdb, query);
          return;
        } else if ("query".equals(endpoint)) {
          printQueryStats(query);
          return;
        } else if ("region_clients".equals(endpoint)) {
          printRegionClientStats(tsdb, query);
          return;
        }
      } catch (IllegalArgumentException e) {
        // this is thrown if the url doesn't start with /api. To maintain backwards
        // compatibility with the /stats endpoint we can catch and continue here.
      }
      
      final boolean canonical = tsdb.getConfig().getBoolean("tsd.stats.canonical");
      
      // if we don't have an API request we need to respond with the 1.x version
      if (query.apiVersion() < 1) {
        final boolean json = query.hasQueryStringParam("json");
        final StringBuilder buf = json ? null : new StringBuilder(2048);
        final ArrayList<String> stats = json ? new ArrayList<String>(64) : null;
        final ASCIICollector collector = new ASCIICollector("tsd", buf, stats);
        doCollectStats(tsdb, collector, canonical);
        if (json) {
          query.sendReply(JSON.serializeToBytes(stats));
        } else {
          query.sendReply(buf);
        }
        return;
      }
      
      // we have an API version, so go newschool
      final List<IncomingDataPoint> dps = new ArrayList<IncomingDataPoint>(64);
      final SerializerCollector collector = new SerializerCollector("tsd", dps, 
          canonical);
      ConnectionManager.collectStats(collector);
      RpcHandler.collectStats(collector);
      RpcManager.collectStats(collector);
      tsdb.collectStats(collector);
      query.sendReply(query.serializer().formatStatsV1(dps));
    }