Package co.cask.cdap.metrics.transport

Examples of co.cask.cdap.metrics.transport.MetricsRecord


    // Currently the test framework only supports system metrics.
    if (scope != MetricsScope.SYSTEM) {
      return;
    }
    while (metrics.hasNext()) {
      MetricsRecord metricsRecord = metrics.next();
      String context = metricsRecord.getContext();
      // Remove the last part, which is the runID
      int idx = context.lastIndexOf('.');
      if (idx >= 0) {
        context = context.substring(0, idx);
      }
      RuntimeStats.count(String.format("%s.%s", context, metricsRecord.getName()), metricsRecord.getValue());
    }
  }
View Full Code Here


   * @throws OperationException When there is an error updating the table.
   */
  public void update(Iterator<MetricsRecord> records) throws OperationException {
    try {
      while (records.hasNext()) {
        MetricsRecord record = records.next();
        byte[] rowKey = getKey(record.getContext(), record.getName(), record.getRunId());
        Map<byte[], Long> increments = Maps.newTreeMap(Bytes.BYTES_COMPARATOR);

        // The no tag value
        increments.put(Bytes.toBytes(MetricsConstants.EMPTY_TAG), (long) record.getValue());

        // For each tag, increments corresponding values
        for (TagMetric tag : record.getTags()) {
          increments.put(Bytes.toBytes(tag.getTag()), (long) tag.getValue());
        }
        aggregatesTable.increment(rowKey, increments);
      }
    } catch (Exception e) {
View Full Code Here

    encoderOutputStream.reset();

    KafkaPublisher.Preparer preparer = publisher.prepare(topicPrefix + "." + scope.name().toLowerCase());
    while (metrics.hasNext()) {
      // Encode each MetricRecord into bytes and make it an individual kafka message in a message set.
      MetricsRecord record = metrics.next();
      recordWriter.encode(record, encoder);
      preparer.add(ByteBuffer.wrap(encoderOutputStream.toByteArray()), record.getContext());
      encoderOutputStream.reset();
    }

    preparer.send();
  }
View Full Code Here

          Map.Entry<EmitterKey, AggregatedMetricsEmitter> entry = iterator.next();
          if (entry.getKey().getCollectorKey().getScope() != scope) {
            continue;
          }

          MetricsRecord metricsRecord = entry.getValue().emit(timestamp);
          if (metricsRecord.getValue() != 0) {
            LOG.trace("Emit metric {}", metricsRecord);
            return metricsRecord;
          }
        }
        return endOfData();
View Full Code Here

    ImmutableList.Builder<TagMetric> builder = ImmutableList.builder();
    int value = this.value.getAndSet(0);
    for (Map.Entry<String, AtomicInteger> entry : tagValues.asMap().entrySet()) {
      builder.add(new TagMetric(entry.getKey(), entry.getValue().getAndSet(0)));
    }
    return new MetricsRecord(context, runId, name, builder.build(), timestamp, value);
  }
View Full Code Here


  @Override
  protected void publish(MetricsScope scope, Iterator<MetricsRecord> metrics) throws Exception {
    while (metrics.hasNext()) {
      MetricsRecord record = metrics.next();
      String context = record.getContext();

      // Context is expected to look like appId.b.programId.[m|r].[taskId]
      String counterGroup;
      String contextParts[] = splitPattern.split(context);
      //TODO: Refactor to support any context
      if (context.equals(Constants.Metrics.DATASET_CONTEXT)) {
        counterGroup = "cdap.dataset";
      } else if ("m".equals(contextParts[3])) {
        counterGroup = "cdap.mapper";
      } else if ("r".equals(contextParts[3])) {
        counterGroup = "cdap.reducer";
      } else {
        LOG.error("could not determine if the metric is a map or reduce metric from context {}, skipping...", context);
        continue;
      }

      counterGroup += "." + scope.name();

      String counterName = getCounterName(record.getName());
      taskContext.getCounter(counterGroup, counterName).increment(record.getValue());
      for (TagMetric tag : record.getTags()) {
        counterName = getCounterName(record.getName(), tag.getTag());
        if (counterName != null) {
          taskContext.getCounter(counterGroup, counterName).increment(tag.getValue());
        }
      }
    }
View Full Code Here

TOP

Related Classes of co.cask.cdap.metrics.transport.MetricsRecord

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.