Search in sources :

Example 1 with Emitter

use of com.metamx.emitter.core.Emitter in project druid by druid-io.

the class GraphiteEmitter method emit.

@Override
public void emit(Event event) {
    if (!started.get()) {
        throw new ISE("WTF emit was called while service is not started yet");
    }
    if (event instanceof ServiceMetricEvent) {
        final GraphiteEvent graphiteEvent = graphiteEventConverter.druidEventToGraphite((ServiceMetricEvent) event);
        if (graphiteEvent == null) {
            return;
        }
        try {
            final boolean isSuccessful = eventsQueue.offer(graphiteEvent, graphiteEmitterConfig.getEmitWaitTime(), TimeUnit.MILLISECONDS);
            if (!isSuccessful) {
                if (countLostEvents.getAndIncrement() % 1000 == 0) {
                    log.error("Lost total of [%s] events because of emitter queue is full. Please increase the capacity or/and the consumer frequency", countLostEvents.get());
                }
            }
        } catch (InterruptedException e) {
            log.error(e, "got interrupted with message [%s]", e.getMessage());
            Thread.currentThread().interrupt();
        }
    } else if (!emitterList.isEmpty() && event instanceof AlertEvent) {
        for (Emitter emitter : emitterList) {
            emitter.emit(event);
        }
    } else if (event instanceof AlertEvent) {
        AlertEvent alertEvent = (AlertEvent) event;
        log.error("The following alert is dropped, description is [%s], severity is [%s]", alertEvent.getDescription(), alertEvent.getSeverity());
    } else {
        log.error("unknown event type [%s]", event.getClass());
    }
}
Also used : Emitter(com.metamx.emitter.core.Emitter) AlertEvent(com.metamx.emitter.service.AlertEvent) ISE(io.druid.java.util.common.ISE) ServiceMetricEvent(com.metamx.emitter.service.ServiceMetricEvent)

Example 2 with Emitter

use of com.metamx.emitter.core.Emitter in project druid by druid-io.

the class MockMemcachedClient method testMonitor.

@Test
public void testMonitor() throws Exception {
    final MemcachedCache cache = MemcachedCache.create(memcachedCacheConfig);
    final Emitter emitter = EasyMock.createNiceMock(Emitter.class);
    final Collection<Event> events = new ArrayList<>();
    final ServiceEmitter serviceEmitter = new ServiceEmitter("service", "host", emitter) {

        @Override
        public void emit(Event event) {
            events.add(event);
        }
    };
    while (events.isEmpty()) {
        Thread.sleep(memcachedCacheConfig.getTimeout());
        cache.doMonitor(serviceEmitter);
    }
    Assert.assertFalse(events.isEmpty());
    ObjectMapper mapper = new DefaultObjectMapper();
    for (Event event : events) {
        log.debug("Found event `%s`", mapper.writeValueAsString(event.toMap()));
    }
}
Also used : ServiceEmitter(com.metamx.emitter.service.ServiceEmitter) Emitter(com.metamx.emitter.core.Emitter) ServiceEmitter(com.metamx.emitter.service.ServiceEmitter) ArrayList(java.util.ArrayList) Event(com.metamx.emitter.core.Event) DefaultObjectMapper(io.druid.jackson.DefaultObjectMapper) DefaultObjectMapper(io.druid.jackson.DefaultObjectMapper) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 3 with Emitter

use of com.metamx.emitter.core.Emitter in project druid by druid-io.

the class ComposingEmitterModuleTest method testGetEmitterViaRealGuice.

@Test
public void testGetEmitterViaRealGuice() {
    Injector injector = Guice.createInjector(new DruidGuiceExtensions(), new LifecycleModule(), new Module() {

        @Override
        public void configure(Binder binder) {
            Properties props = new Properties();
            props.put("druid.emitter.composing.emitters", "[\"" + testEmitterType + "\"]");
            binder.bind(Properties.class).toInstance(props);
            binder.bind(Validator.class).toInstance(Validation.buildDefaultValidatorFactory().getValidator());
            binder.bind(Emitter.class).annotatedWith(Names.named(testEmitterType)).toInstance(emitter);
        }
    }, new ComposingEmitterModule());
    injector.getInstance(Key.get(Emitter.class, Names.named("composing"))).start();
    EasyMock.verify(emitter);
}
Also used : Binder(com.google.inject.Binder) Emitter(com.metamx.emitter.core.Emitter) DruidGuiceExtensions(io.druid.guice.DruidGuiceExtensions) Injector(com.google.inject.Injector) Module(com.google.inject.Module) LifecycleModule(io.druid.guice.LifecycleModule) ComposingEmitterModule(io.druid.server.initialization.ComposingEmitterModule) Properties(java.util.Properties) ComposingEmitterModule(io.druid.server.initialization.ComposingEmitterModule) LifecycleModule(io.druid.guice.LifecycleModule) Test(org.junit.Test)

Example 4 with Emitter

use of com.metamx.emitter.core.Emitter in project druid by druid-io.

the class ComposingEmitterModuleTest method testGetEmitter.

@Test
public void testGetEmitter() {
    ComposingEmitterConfig config = EasyMock.createMock(ComposingEmitterConfig.class);
    EasyMock.expect(config.getEmitters()).andReturn(Lists.newArrayList(testEmitterType)).anyTimes();
    Injector injector = EasyMock.createMock(Injector.class);
    EasyMock.expect(injector.getInstance(Key.get(Emitter.class, Names.named(testEmitterType)))).andReturn(emitter);
    EasyMock.replay(config, injector);
    Emitter composingEmitter = new ComposingEmitterModule().getEmitter(config, injector);
    composingEmitter.start();
    EasyMock.verify(config, emitter, injector);
}
Also used : Emitter(com.metamx.emitter.core.Emitter) Injector(com.google.inject.Injector) ComposingEmitterConfig(io.druid.server.initialization.ComposingEmitterConfig) ComposingEmitterModule(io.druid.server.initialization.ComposingEmitterModule) Test(org.junit.Test)

Aggregations

Emitter (com.metamx.emitter.core.Emitter)4 Test (org.junit.Test)3 Injector (com.google.inject.Injector)2 ComposingEmitterModule (io.druid.server.initialization.ComposingEmitterModule)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 Binder (com.google.inject.Binder)1 Module (com.google.inject.Module)1 Event (com.metamx.emitter.core.Event)1 AlertEvent (com.metamx.emitter.service.AlertEvent)1 ServiceEmitter (com.metamx.emitter.service.ServiceEmitter)1 ServiceMetricEvent (com.metamx.emitter.service.ServiceMetricEvent)1 DruidGuiceExtensions (io.druid.guice.DruidGuiceExtensions)1 LifecycleModule (io.druid.guice.LifecycleModule)1 DefaultObjectMapper (io.druid.jackson.DefaultObjectMapper)1 ISE (io.druid.java.util.common.ISE)1 ComposingEmitterConfig (io.druid.server.initialization.ComposingEmitterConfig)1 ArrayList (java.util.ArrayList)1 Properties (java.util.Properties)1