use of com.twitter.heron.common.utils.metrics.MetricsCollector in project incubator-heron by apache.
the class Slave method registerTasksWithSlave.
private void registerTasksWithSlave() {
// Create a new MetricsCollector with the clean slaveLooper and register its task
metricsCollector = new MetricsCollector(slaveLooper, metricsOutCommunicator);
// registering the handling of control msg
handleControlMessage();
// instance task will be registered when instance.start() is called
}
use of com.twitter.heron.common.utils.metrics.MetricsCollector in project incubator-heron by apache.
the class GlobalMetricsTest method testGlobalMetrics.
@Test
public void testGlobalMetrics() {
MetricsCollector fakeCollector = new MetricsCollector(new FakeWakeableLooper(), null);
TopologyContext fakeContext = new TopologyContextImpl(new HashMap<String, Object>(), TopologyAPI.Topology.getDefaultInstance(), new HashMap<Integer, String>(), 0, fakeCollector);
GlobalMetrics.init(fakeContext, Duration.ofSeconds(5));
GlobalMetrics.incr("mycounter");
Map<String, Long> metricsContent = GlobalMetrics.getUnderlyingCounter().getValueAndReset();
assertTrue(metricsContent.containsKey("mycounter"));
assertEquals(1, metricsContent.size());
assertEquals(new Long(1), metricsContent.get("mycounter"));
// Increment two different counters
GlobalMetrics.incr("mycounter1");
GlobalMetrics.incr("mycounter2");
GlobalMetrics.incr("mycounter1");
metricsContent = GlobalMetrics.getUnderlyingCounter().getValueAndReset();
assertTrue(metricsContent.containsKey("mycounter"));
assertTrue(metricsContent.containsKey("mycounter1"));
assertTrue(metricsContent.containsKey("mycounter2"));
assertEquals(3L, metricsContent.size());
assertEquals(new Long(0), metricsContent.get("mycounter"));
assertEquals(new Long(1), metricsContent.get("mycounter2"));
assertEquals(new Long(2), metricsContent.get("mycounter1"));
}
Aggregations