Search in sources :

Example 6 with Count

use of org.apache.kafka.common.metrics.stats.Count in project kafka by apache.

the class MetricsTest method testHierarchicalSensors.

@Test
public void testHierarchicalSensors() {
    Sensor parent1 = metrics.sensor("test.parent1");
    parent1.add(metrics.metricName("test.parent1.count", "grp1"), new Count());
    Sensor parent2 = metrics.sensor("test.parent2");
    parent2.add(metrics.metricName("test.parent2.count", "grp1"), new Count());
    Sensor child1 = metrics.sensor("test.child1", parent1, parent2);
    child1.add(metrics.metricName("test.child1.count", "grp1"), new Count());
    Sensor child2 = metrics.sensor("test.child2", parent1);
    child2.add(metrics.metricName("test.child2.count", "grp1"), new Count());
    Sensor grandchild = metrics.sensor("test.grandchild", child1);
    grandchild.add(metrics.metricName("test.grandchild.count", "grp1"), new Count());
    /* increment each sensor one time */
    parent1.record();
    parent2.record();
    child1.record();
    child2.record();
    grandchild.record();
    double p1 = parent1.metrics().get(0).value();
    double p2 = parent2.metrics().get(0).value();
    double c1 = child1.metrics().get(0).value();
    double c2 = child2.metrics().get(0).value();
    double gc = grandchild.metrics().get(0).value();
    /* each metric should have a count equal to one + its children's count */
    assertEquals(1.0, gc, EPS);
    assertEquals(1.0 + gc, c1, EPS);
    assertEquals(1.0, c2, EPS);
    assertEquals(1.0 + c1, p2, EPS);
    assertEquals(1.0 + c1 + c2, p1, EPS);
    assertEquals(Arrays.asList(child1, child2), metrics.childrenSensors().get(parent1));
    assertEquals(Arrays.asList(child1), metrics.childrenSensors().get(parent2));
    assertNull(metrics.childrenSensors().get(grandchild));
}
Also used : Count(org.apache.kafka.common.metrics.stats.Count) Test(org.junit.Test)

Example 7 with Count

use of org.apache.kafka.common.metrics.stats.Count in project kafka by apache.

the class MetricsTest method testRemoveSensor.

@Test
public void testRemoveSensor() {
    int size = metrics.metrics().size();
    Sensor parent1 = metrics.sensor("test.parent1");
    parent1.add(metrics.metricName("test.parent1.count", "grp1"), new Count());
    Sensor parent2 = metrics.sensor("test.parent2");
    parent2.add(metrics.metricName("test.parent2.count", "grp1"), new Count());
    Sensor child1 = metrics.sensor("test.child1", parent1, parent2);
    child1.add(metrics.metricName("test.child1.count", "grp1"), new Count());
    Sensor child2 = metrics.sensor("test.child2", parent2);
    child2.add(metrics.metricName("test.child2.count", "grp1"), new Count());
    Sensor grandChild1 = metrics.sensor("test.gchild2", child2);
    grandChild1.add(metrics.metricName("test.gchild2.count", "grp1"), new Count());
    Sensor sensor = metrics.getSensor("test.parent1");
    assertNotNull(sensor);
    metrics.removeSensor("test.parent1");
    assertNull(metrics.getSensor("test.parent1"));
    assertNull(metrics.metrics().get(metrics.metricName("test.parent1.count", "grp1")));
    assertNull(metrics.getSensor("test.child1"));
    assertNull(metrics.childrenSensors().get(sensor));
    assertNull(metrics.metrics().get(metrics.metricName("test.child1.count", "grp1")));
    sensor = metrics.getSensor("test.gchild2");
    assertNotNull(sensor);
    metrics.removeSensor("test.gchild2");
    assertNull(metrics.getSensor("test.gchild2"));
    assertNull(metrics.childrenSensors().get(sensor));
    assertNull(metrics.metrics().get(metrics.metricName("test.gchild2.count", "grp1")));
    sensor = metrics.getSensor("test.child2");
    assertNotNull(sensor);
    metrics.removeSensor("test.child2");
    assertNull(metrics.getSensor("test.child2"));
    assertNull(metrics.childrenSensors().get(sensor));
    assertNull(metrics.metrics().get(metrics.metricName("test.child2.count", "grp1")));
    sensor = metrics.getSensor("test.parent2");
    assertNotNull(sensor);
    metrics.removeSensor("test.parent2");
    assertNull(metrics.getSensor("test.parent2"));
    assertNull(metrics.childrenSensors().get(sensor));
    assertNull(metrics.metrics().get(metrics.metricName("test.parent2.count", "grp1")));
    assertEquals(size, metrics.metrics().size());
}
Also used : Count(org.apache.kafka.common.metrics.stats.Count) Test(org.junit.Test)

Example 8 with Count

use of org.apache.kafka.common.metrics.stats.Count in project kafka by apache.

the class MetricsTest method testEventWindowing.

@Test
public void testEventWindowing() {
    Count count = new Count();
    MetricConfig config = new MetricConfig().eventWindow(1).samples(2);
    count.record(config, 1.0, time.milliseconds());
    count.record(config, 1.0, time.milliseconds());
    assertEquals(2.0, count.measure(config, time.milliseconds()), EPS);
    // first event times out
    count.record(config, 1.0, time.milliseconds());
    assertEquals(2.0, count.measure(config, time.milliseconds()), EPS);
}
Also used : Count(org.apache.kafka.common.metrics.stats.Count) Test(org.junit.Test)

Example 9 with Count

use of org.apache.kafka.common.metrics.stats.Count in project kafka by apache.

the class MetricsTest method testRemoveInactiveMetrics.

@Test
public void testRemoveInactiveMetrics() {
    Sensor s1 = metrics.sensor("test.s1", null, 1);
    s1.add(metrics.metricName("test.s1.count", "grp1"), new Count());
    Sensor s2 = metrics.sensor("test.s2", null, 3);
    s2.add(metrics.metricName("test.s2.count", "grp1"), new Count());
    Metrics.ExpireSensorTask purger = metrics.new ExpireSensorTask();
    purger.run();
    assertNotNull("Sensor test.s1 must be present", metrics.getSensor("test.s1"));
    assertNotNull("MetricName test.s1.count must be present", metrics.metrics().get(metrics.metricName("test.s1.count", "grp1")));
    assertNotNull("Sensor test.s2 must be present", metrics.getSensor("test.s2"));
    assertNotNull("MetricName test.s2.count must be present", metrics.metrics().get(metrics.metricName("test.s2.count", "grp1")));
    time.sleep(1001);
    purger.run();
    assertNull("Sensor test.s1 should have been purged", metrics.getSensor("test.s1"));
    assertNull("MetricName test.s1.count should have been purged", metrics.metrics().get(metrics.metricName("test.s1.count", "grp1")));
    assertNotNull("Sensor test.s2 must be present", metrics.getSensor("test.s2"));
    assertNotNull("MetricName test.s2.count must be present", metrics.metrics().get(metrics.metricName("test.s2.count", "grp1")));
    // record a value in sensor s2. This should reset the clock for that sensor.
    // It should not get purged at the 3 second mark after creation
    s2.record();
    time.sleep(2000);
    purger.run();
    assertNotNull("Sensor test.s2 must be present", metrics.getSensor("test.s2"));
    assertNotNull("MetricName test.s2.count must be present", metrics.metrics().get(metrics.metricName("test.s2.count", "grp1")));
    // After another 1 second sleep, the metric should be purged
    time.sleep(1000);
    purger.run();
    assertNull("Sensor test.s2 should have been purged", metrics.getSensor("test.s1"));
    assertNull("MetricName test.s2.count should have been purged", metrics.metrics().get(metrics.metricName("test.s1.count", "grp1")));
    // After purging, it should be possible to recreate a metric
    s1 = metrics.sensor("test.s1", null, 1);
    s1.add(metrics.metricName("test.s1.count", "grp1"), new Count());
    assertNotNull("Sensor test.s1 must be present", metrics.getSensor("test.s1"));
    assertNotNull("MetricName test.s1.count must be present", metrics.metrics().get(metrics.metricName("test.s1.count", "grp1")));
}
Also used : Count(org.apache.kafka.common.metrics.stats.Count) Test(org.junit.Test)

Aggregations

Count (org.apache.kafka.common.metrics.stats.Count)9 Test (org.junit.Test)8 Avg (org.apache.kafka.common.metrics.stats.Avg)3 Max (org.apache.kafka.common.metrics.stats.Max)3 Min (org.apache.kafka.common.metrics.stats.Min)2 Percentile (org.apache.kafka.common.metrics.stats.Percentile)2 Percentiles (org.apache.kafka.common.metrics.stats.Percentiles)2 Rate (org.apache.kafka.common.metrics.stats.Rate)2 SimpleRate (org.apache.kafka.common.metrics.stats.SimpleRate)2 Metrics (org.apache.kafka.common.metrics.Metrics)1 Sensor (org.apache.kafka.common.metrics.Sensor)1 Total (org.apache.kafka.common.metrics.stats.Total)1