Exemplo n.º 1
0
  @Override
  public AsyncFuture<Void> run(final ShellIO io, final TaskParameters base) throws Exception {
    final Parameters params = (Parameters) base;

    final String queryString = params.query.stream().collect(Collectors.joining(" "));

    final ObjectMapper indent = mapper.copy();
    indent.configure(SerializationFeature.INDENT_OUTPUT, true);

    final QueryOptions.Builder optionsBuilder = QueryOptions.builder().tracing(params.tracing);

    params.dataLimit.ifPresent(optionsBuilder::dataLimit);
    params.groupLimit.ifPresent(optionsBuilder::groupLimit);
    params.seriesLimit.ifPresent(optionsBuilder::seriesLimit);

    final QueryOptions options = optionsBuilder.build();

    final Optional<QueryDateRange> range =
        Optional.of(new QueryDateRange.Relative(TimeUnit.DAYS, 1));

    return query
        .useGroup(params.group)
        .query(
            query
                .newQueryFromString(queryString)
                .options(Optional.of(options))
                .rangeIfAbsent(range)
                .build())
        .directTransform(
            result -> {
              for (final RequestError e : result.getErrors()) {
                io.out().println(String.format("ERR: %s", e.toString()));
              }

              io.out().println(String.format("LIMITS: %s", result.getLimits().getLimits()));

              for (final ShardedResultGroup resultGroup : result.getGroups()) {
                final MetricCollection group = resultGroup.getMetrics();

                io.out()
                    .println(
                        String.format(
                            "%s: %s %s",
                            group.getType(),
                            resultGroup.getShard(),
                            indent.writeValueAsString(resultGroup.getSeries())));
                io.out().println(indent.writeValueAsString(group.getData()));
                io.out().flush();
              }

              io.out().println("TRACE:");
              result.getTrace().formatTrace(io.out());
              io.out().flush();

              return null;
            });
  }
Exemplo n.º 2
0
 public Iterable<Metric> all() {
   return data.getDataAs(Metric.class);
 }
Exemplo n.º 3
0
 public boolean isEmpty() {
   return data.isEmpty();
 }