Java Code Examples for org.apache.kafka.common.metrics.KafkaMetric#metricName()

The following examples show how to use org.apache.kafka.common.metrics.KafkaMetric#metricName() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MetricsUtils.java    From cruise-control with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/**
 * Create a Cruise Control Metric.
 *
 * @param kafkaMetric Kafka metric name.
 * @param now The current time in milliseconds.
 * @param brokerId Broker Id.
 * @return KafkaMetric converted as a CruiseControlMetric.
 */
public static CruiseControlMetric toCruiseControlMetric(KafkaMetric kafkaMetric, long now, int brokerId) {
  org.apache.kafka.common.MetricName metricName = kafkaMetric.metricName();
  if (!(kafkaMetric.metricValue() instanceof Double)) {
    throw new IllegalArgumentException(String.format("Cannot convert non-double (%s) KafkaMetric %s to a Cruise Control"
                                                     + " metric for broker %d", kafkaMetric.metricValue().getClass(),
                                                     kafkaMetric.metricName(), brokerId));
  }

  CruiseControlMetric ccm = toCruiseControlMetric(now, brokerId, metricName.name(), metricName.tags(), (double) kafkaMetric.metricValue());
  if (ccm == null) {
    throw new IllegalArgumentException(String.format("Cannot convert KafkaMetric %s to a Cruise Control metric for "
                                                         + "broker %d at time %d", kafkaMetric.metricName(), brokerId, now));
  }
  return ccm;
}
 
Example 2
Source File: DropwizardReporter.java    From kafka-dropwizard-reporter with Apache License 2.0 6 votes vote down vote up
private static String dropwizardMetricName(KafkaMetric kafkaMetric) {
    MetricName name = kafkaMetric.metricName();

    List<String> nameParts = new ArrayList<String>(2);
    nameParts.add(name.group());
    nameParts.addAll(name.tags().values());
    nameParts.add(name.name());

    StringBuilder builder = new StringBuilder();
    for (String namePart : nameParts) {
        builder.append(namePart);
        builder.append(".");
    }
    builder.setLength(builder.length() - 1);  // Remove the trailing dot.
    String processedName = builder.toString().replace(' ', '_').replace("\\.", "_");

    return MetricRegistry.name(METRIC_PREFIX, processedName);
}
 
Example 3
Source File: ServoReporter.java    From suro with Apache License 2.0 5 votes vote down vote up
private void addMetric(KafkaMetric metric) {
    MetricName metricName = metric.metricName();
    MonitorConfig.Builder builder = MonitorConfig.builder(metricName.name())
        .withTag("group", metricName.group());
    for(Map.Entry<String, String> tag : metricName.tags().entrySet()) {
        builder.withTag(tag.getKey(), tag.getValue());
    }
    MonitorConfig monitorConfig = builder.build();
    gauges.put(Servo.getDoubleGauge(monitorConfig), metric);
}
 
Example 4
Source File: Kafka09ConsumerClient.java    From incubator-gobblin with Apache License 2.0 4 votes vote down vote up
private String canonicalMetricName(KafkaMetric kafkaMetric) {
  MetricName name = kafkaMetric.metricName();
  return canonicalMetricName(name.group(), name.tags().values(), name.name());
}
 
Example 5
Source File: StatsdMetricsReporter.java    From kafka-statsd-metrics2 with Apache License 2.0 4 votes vote down vote up
private String getMetricName(final KafkaMetric metric) {
  MetricName metricName = metric.metricName();

  return METRIC_PREFIX + metricName.group() + "." + metricName.name();
}
 
Example 6
Source File: DropwizardMetricsReporter.java    From emodb with Apache License 2.0 3 votes vote down vote up
private static String metricName(KafkaMetric kafkaMetric) {
    MetricName name = kafkaMetric.metricName();

    TaggedName.TaggedNameBuilder builder = new TaggedName.TaggedNameBuilder()
            .metricName(MetricRegistry.name(METRIC_PREFIX, name.group(), name.name()));

    name.tags().forEach(builder::addTag);

    return builder.build().encode();
}