public Input.IoStats getGlobalInputIo(Input input) {
    final Input.IoStats ioStats = new Input.IoStats();

    final String inputId = input.getId();
    final String type = input.getType();

    try {
      MultiMetricRequest request = new MultiMetricRequest();
      final String read_bytes = qualifiedIOMetricName(type, inputId, "read_bytes", false);
      final String read_bytes_total = qualifiedIOMetricName(type, inputId, "read_bytes", true);
      final String written_bytes = qualifiedIOMetricName(type, inputId, "written_bytes", false);
      final String written_bytes_total =
          qualifiedIOMetricName(type, inputId, "written_bytes", true);
      request.metrics =
          new String[] {read_bytes, read_bytes_total, written_bytes, written_bytes_total};

      final Map<Node, MetricsListResponse> results =
          api.path(routes.MetricsResource().multipleMetrics(), MetricsListResponse.class)
              .body(request)
              .expect(200, 404)
              .executeOnAll();

      for (MetricsListResponse response : results.values()) {
        final Map<String, Metric> metrics = response.getMetrics();

        ioStats.readBytes += asLong(read_bytes, metrics);
        ioStats.readBytesTotal += asLong(read_bytes_total, metrics);
        ioStats.writtenBytes += asLong(written_bytes, metrics);
        ioStats.writtenBytesTotal += asLong(written_bytes_total, metrics);
      }

      for (Radio radio : nodeService.radios().values()) {
        try {
          final MetricsListResponse radioResponse =
              api.path(
                      routes.radio().MetricsResource().multipleMetrics(), MetricsListResponse.class)
                  .body(request)
                  .radio(radio)
                  .expect(200, 404)
                  .execute();
          final Map<String, Metric> metrics = radioResponse.getMetrics();

          ioStats.readBytes += asLong(read_bytes, metrics);
          ioStats.readBytesTotal += asLong(read_bytes_total, metrics);
          ioStats.writtenBytes += asLong(written_bytes, metrics);
          ioStats.writtenBytesTotal += asLong(written_bytes_total, metrics);
        } catch (APIException | IOException e) {
          LOG.error("Unable to load metrics for radio node {}", radio.getId());
        }
      }

    } catch (APIException | IOException e) {
      LOG.error("Unable to load master node", e);
    }
    return ioStats;
  }
Beispiel #2
0
 public Map<String, Metric> getMetrics(String namespace) throws APIException, IOException {
   MetricsListResponse response =
       api.path(routes.MetricsResource().byNamespace(namespace), MetricsListResponse.class)
           .node(this)
           .expect(200)
           .execute();
   if (response == null) {
     return Collections.emptyMap();
   }
   return response.getMetrics();
 }