Handles fetching statistics from all over the code, collating them in a string buffer or list, and emitting them to the caller. Stats are collected lazily, i.e. only when this method is called. This class supports the 1.x style HTTP call as well as the 2.x style API calls. @since 2.0
| 48 | * @since 2.0 |
| 49 | */ |
| 50 | public final class StatsRpc implements TelnetRpc, HttpRpc { |
| 51 | private static final Logger LOG = LoggerFactory.getLogger(StatsRpc.class); |
| 52 | |
| 53 | /** |
| 54 | * Telnet RPC responder that returns the stats in ASCII style |
| 55 | * @param tsdb The TSDB to use for fetching stats |
| 56 | * @param chan The netty channel to respond on |
| 57 | * @param cmd call parameters |
| 58 | */ |
| 59 | public Deferred<Object> execute(final TSDB tsdb, final Channel chan, |
| 60 | final String[] cmd) { |
| 61 | final boolean canonical = tsdb.getConfig().getBoolean("tsd.stats.canonical"); |
| 62 | final StringBuilder buf = new StringBuilder(1024); |
| 63 | final ASCIICollector collector = new ASCIICollector("tsd", buf, null); |
| 64 | doCollectStats(tsdb, collector, canonical); |
| 65 | chan.write(buf.toString()); |
| 66 | return Deferred.fromResult(null); |
| 67 | } |
| 68 | |
| 69 | /** |
| 70 | * HTTP resposne handler |
| 71 | * @param tsdb The TSDB to which we belong |
| 72 | * @param query The query to parse and respond to |
| 73 | */ |
| 74 | public void execute(final TSDB tsdb, final HttpQuery query) { |
| 75 | // only accept GET/POST |
| 76 | if (query.method() != HttpMethod.GET && query.method() != HttpMethod.POST) { |
| 77 | throw new BadRequestException(HttpResponseStatus.METHOD_NOT_ALLOWED, |
| 78 | "Method not allowed", "The HTTP method [" + query.method().getName() + |
| 79 | "] is not permitted for this endpoint"); |
| 80 | } |
| 81 | |
| 82 | try { |
| 83 | final String[] uri = query.explodeAPIPath(); |
| 84 | final String endpoint = uri.length > 1 ? uri[1].toLowerCase() : ""; |
| 85 | |
| 86 | // Handle /threads and /regions. |
| 87 | if ("threads".equals(endpoint)) { |
| 88 | printThreadStats(query); |
| 89 | return; |
| 90 | } else if ("jvm".equals(endpoint)) { |
| 91 | printJVMStats(tsdb, query); |
| 92 | return; |
| 93 | } else if ("query".equals(endpoint)) { |
| 94 | printQueryStats(query); |
| 95 | return; |
| 96 | } else if ("region_clients".equals(endpoint)) { |
| 97 | printRegionClientStats(tsdb, query); |
| 98 | return; |
| 99 | } |
| 100 | } catch (IllegalArgumentException e) { |
| 101 | // this is thrown if the url doesn't start with /api. To maintain backwards |
| 102 | // compatibility with the /stats endpoint we can catch and continue here. |
| 103 | } |
| 104 | |
| 105 | final boolean canonical = tsdb.getConfig().getBoolean("tsd.stats.canonical"); |
| 106 | |
| 107 | // if we don't have an API request we need to respond with the 1.x version |
nothing calls this directly
no outgoing calls
no test coverage detected
searching dependent graphs…