use of org.apache.kafka.common.metrics.KafkaMetric in project cruise-control by linkedin.
the class CruiseControlMetricsReporter method init.
@Override
public void init(List<KafkaMetric> metrics) {
for (KafkaMetric kafkaMetric : metrics) {
addMetricIfInterested(kafkaMetric);
}
LOG.info("Added {} Kafka metrics for Cruise Control metrics during initialization.", _interestedMetrics.size());
_metricsReporterRunner = new KafkaThread("CruiseControlMetricsReporterRunner", this, true);
_yammerMetricProcessor = new YammerMetricProcessor();
_metricsReporterRunner.start();
}
use of org.apache.kafka.common.metrics.KafkaMetric in project cruise-control by linkedin.
the class CruiseControlMetricsReporter method reportKafkaMetrics.
private void reportKafkaMetrics(long now) {
LOG.debug("Reporting KafkaMetrics. {}", _interestedMetrics.values());
for (KafkaMetric metric : _interestedMetrics.values()) {
sendCruiseControlMetric(MetricsUtils.toCruiseControlMetric(metric, now, _brokerId));
}
LOG.debug("Finished reporting KafkaMetrics.");
}
use of org.apache.kafka.common.metrics.KafkaMetric in project ksql by confluentinc.
the class StorageUtilizationMetricsReporterTest method mockMetric.
private KafkaMetric mockMetric(final String group, final String name, Object value, final Map<String, String> tags) {
final KafkaMetric metric = mock(KafkaMetric.class);
when(metric.metricName()).thenReturn(new MetricName(name, group, "", tags));
when(metric.metricValue()).thenReturn(value);
return metric;
}
use of org.apache.kafka.common.metrics.KafkaMetric in project ksql by confluentinc.
the class StorageUtilizationMetricsReporterTest method shouldRemoveObsoleteStateStoreMetrics.
@Test
public void shouldRemoveObsoleteStateStoreMetrics() {
// Given:
listener.metricChange(mockMetric(KAFKA_METRIC_GROUP, KAFKA_METRIC_NAME, BigInteger.valueOf(2), ImmutableMap.of("store-id", "s1", "task-id", "t1", "thread-id", THREAD_ID)));
final KafkaMetric metric = mockMetric(KAFKA_METRIC_GROUP, KAFKA_METRIC_NAME, BigInteger.valueOf(6), ImmutableMap.of("store-id", "s2", "task-id", "t1", "thread-id", THREAD_ID));
listener.metricChange(metric);
final Gauge<?> taskGauge = verifyAndGetRegisteredMetric(TASK_STORAGE_METRIC, TASK_ONE_TAGS);
Object taskValue = taskGauge.value(null, 0);
assertThat(taskValue, equalTo(BigInteger.valueOf(8)));
// When:
listener.metricRemoval(metric);
// Then:
taskValue = taskGauge.value(null, 0);
assertThat(taskValue, equalTo(BigInteger.valueOf(2)));
}
use of org.apache.kafka.common.metrics.KafkaMetric in project ksql by confluentinc.
the class ProducerCollector method addSensor.
private void addSensor(final String key, final String metricNameString, final MeasurableStat stat, final List<SensorMetric<ProducerRecord<Object, Object>>> results) {
final String name = "prod-" + key + "-" + metricNameString + "-" + id;
final MetricName metricName = new MetricName(metricNameString, "producer-metrics", "producer-" + name, ImmutableMap.of("key", key, "id", id));
final Sensor existingSensor = metrics.getSensor(name);
final Sensor sensor = metrics.sensor(name);
// either a new sensor or a new metric with different id
if (existingSensor == null || metrics.metrics().get(metricName) == null) {
sensor.add(metricName, stat);
}
final KafkaMetric metric = metrics.metrics().get(metricName);
results.add(new SensorMetric<ProducerRecord<Object, Object>>(sensor, metric, time, false) {
void record(final ProducerRecord<Object, Object> record) {
sensor.record(1);
super.record(record);
}
});
}
Aggregations