Search in sources :

Example 1 with ServiceMetricEvent

use of com.metamx.emitter.service.ServiceMetricEvent 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 ServiceMetricEvent

use of com.metamx.emitter.service.ServiceMetricEvent in project druid by druid-io.

the class StatsDEmitter method emit.

@Override
public void emit(Event event) {
    if (event instanceof ServiceMetricEvent) {
        ServiceMetricEvent metricEvent = (ServiceMetricEvent) event;
        String host = metricEvent.getHost();
        String service = metricEvent.getService();
        String metric = metricEvent.getMetric();
        Map<String, Object> userDims = metricEvent.getUserDims();
        Number value = metricEvent.getValue();
        ImmutableList.Builder<String> nameBuilder = new ImmutableList.Builder<>();
        if (config.getIncludeHost()) {
            nameBuilder.add(host);
        }
        nameBuilder.add(service);
        nameBuilder.add(metric);
        StatsDMetric statsDMetric = converter.addFilteredUserDims(service, metric, userDims, nameBuilder);
        if (statsDMetric != null) {
            String fullName = Joiner.on(config.getSeparator()).join(nameBuilder.build()).replaceAll(DRUID_METRIC_SEPARATOR, config.getSeparator()).replaceAll(STATSD_SEPARATOR, config.getSeparator());
            long val = statsDMetric.convertRange ? Math.round(value.doubleValue() * 100) : value.longValue();
            switch(statsDMetric.type) {
                case count:
                    statsd.count(fullName, val);
                    break;
                case timer:
                    statsd.time(fullName, val);
                    break;
                case gauge:
                    statsd.gauge(fullName, val);
                    break;
            }
        } else {
            log.error("Metric=[%s] has no StatsD type mapping", statsDMetric);
        }
    }
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) ServiceMetricEvent(com.metamx.emitter.service.ServiceMetricEvent)

Example 3 with ServiceMetricEvent

use of com.metamx.emitter.service.ServiceMetricEvent in project druid by druid-io.

the class DimensionConverterTest method testConvert.

@Test
public void testConvert() throws Exception {
    DimensionConverter dimensionConverter = new DimensionConverter(new ObjectMapper(), null);
    ServiceMetricEvent event = new ServiceMetricEvent.Builder().setDimension("dataSource", "data-source").setDimension("type", "groupBy").setDimension("interval", "2013/2015").setDimension("some_random_dim1", "random_dim_value1").setDimension("some_random_dim2", "random_dim_value2").setDimension("hasFilters", "no").setDimension("duration", "P1D").setDimension("remoteAddress", "194.0.90.2").setDimension("id", "ID").setDimension("context", "{context}").build(new DateTime(), "query/time", 10).build("broker", "brokerHost1");
    ImmutableList.Builder<String> actual = new ImmutableList.Builder<>();
    StatsDMetric statsDMetric = dimensionConverter.addFilteredUserDims(event.getService(), event.getMetric(), event.getUserDims(), actual);
    assertEquals("correct StatsDMetric.Type", StatsDMetric.Type.timer, statsDMetric.type);
    ImmutableList.Builder<String> expected = new ImmutableList.Builder<>();
    expected.add("data-source");
    expected.add("groupBy");
    assertEquals("correct Dimensions", expected.build(), actual.build());
}
Also used : DimensionConverter(io.druid.emitter.statsd.DimensionConverter) ImmutableList(com.google.common.collect.ImmutableList) ServiceMetricEvent(com.metamx.emitter.service.ServiceMetricEvent) StatsDMetric(io.druid.emitter.statsd.StatsDMetric) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) DateTime(org.joda.time.DateTime) Test(org.junit.Test)

Example 4 with ServiceMetricEvent

use of com.metamx.emitter.service.ServiceMetricEvent in project druid by druid-io.

the class HistoricalMetricsMonitorTest method testSimple.

@Test
public void testSimple() {
    final long size = 5;
    final String dataSource = "dataSource";
    final DataSegment dataSegment = new DataSegment(dataSource, Interval.parse("2014/2015"), "version", ImmutableMap.<String, Object>of(), ImmutableList.<String>of(), ImmutableList.<String>of(), null, 1, size);
    final long maxSize = 10;
    final int priority = 111;
    final String tier = "tier";
    EasyMock.expect(druidServerConfig.getMaxSize()).andReturn(maxSize).once();
    EasyMock.expect(zkCoordinator.getPendingDeleteSnapshot()).andReturn(ImmutableList.of(dataSegment)).once();
    EasyMock.expect(druidServerConfig.getTier()).andReturn(tier).once();
    EasyMock.expect(druidServerConfig.getPriority()).andReturn(priority).once();
    EasyMock.expect(serverManager.getDataSourceSizes()).andReturn(ImmutableMap.of(dataSource, size));
    EasyMock.expect(druidServerConfig.getTier()).andReturn(tier).once();
    EasyMock.expect(druidServerConfig.getPriority()).andReturn(priority).once();
    EasyMock.expect(druidServerConfig.getMaxSize()).andReturn(maxSize).times(2);
    EasyMock.expect(serverManager.getDataSourceCounts()).andReturn(ImmutableMap.of(dataSource, 1L));
    EasyMock.expect(druidServerConfig.getTier()).andReturn(tier).once();
    EasyMock.expect(druidServerConfig.getPriority()).andReturn(priority).once();
    final HistoricalMetricsMonitor monitor = new HistoricalMetricsMonitor(druidServerConfig, serverManager, zkCoordinator);
    final Capture<ServiceEventBuilder<ServiceMetricEvent>> eventCapture = EasyMock.newCapture(CaptureType.ALL);
    serviceEmitter.emit(EasyMock.capture(eventCapture));
    EasyMock.expectLastCall().times(5);
    EasyMock.replay(druidServerConfig, serverManager, zkCoordinator, serviceEmitter);
    monitor.doMonitor(serviceEmitter);
    EasyMock.verify(druidServerConfig, serverManager, zkCoordinator, serviceEmitter);
    final String host = "host";
    final String service = "service";
    Assert.assertTrue(eventCapture.hasCaptured());
    final List<Map<String, Object>> events = Lists.transform(eventCapture.getValues(), new Function<ServiceEventBuilder<ServiceMetricEvent>, Map<String, Object>>() {

        @Nullable
        @Override
        public Map<String, Object> apply(@Nullable ServiceEventBuilder<ServiceMetricEvent> input) {
            final HashMap<String, Object> map = new HashMap<>(input.build(host, service).toMap());
            Assert.assertNotNull(map.remove("feed"));
            Assert.assertNotNull(map.remove("timestamp"));
            Assert.assertNotNull(map.remove("service"));
            Assert.assertNotNull(map.remove("host"));
            return map;
        }
    });
    Assert.assertEquals(ImmutableMap.<String, Object>of("metric", "segment/max", "value", maxSize), events.get(0));
    Assert.assertEquals(ImmutableMap.<String, Object>of("dataSource", dataSource, "metric", "segment/pendingDelete", "priority", String.valueOf(priority), "tier", tier, "value", dataSegment.getSize()), events.get(1));
    Assert.assertEquals(ImmutableMap.<String, Object>of("metric", "segment/used", "value", dataSegment.getSize(), "tier", tier, "priority", String.valueOf(priority), "dataSource", dataSource), events.get(2));
    Assert.assertEquals(ImmutableMap.<String, Object>of("metric", "segment/usedPercent", "value", dataSegment.getSize() * 1.0D / maxSize, "tier", tier, "priority", String.valueOf(priority), "dataSource", dataSource), events.get(3));
    Assert.assertEquals(ImmutableMap.<String, Object>of("metric", "segment/count", "value", 1L, "tier", tier, "priority", String.valueOf(priority), "dataSource", dataSource), events.get(4));
}
Also used : ServiceEventBuilder(com.metamx.emitter.service.ServiceEventBuilder) HashMap(java.util.HashMap) DataSegment(io.druid.timeline.DataSegment) ServiceMetricEvent(com.metamx.emitter.service.ServiceMetricEvent) ImmutableMap(com.google.common.collect.ImmutableMap) HashMap(java.util.HashMap) Map(java.util.Map) Nullable(javax.annotation.Nullable) Test(org.junit.Test)

Aggregations

ServiceMetricEvent (com.metamx.emitter.service.ServiceMetricEvent)4 ImmutableList (com.google.common.collect.ImmutableList)2 Test (org.junit.Test)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 Emitter (com.metamx.emitter.core.Emitter)1 AlertEvent (com.metamx.emitter.service.AlertEvent)1 ServiceEventBuilder (com.metamx.emitter.service.ServiceEventBuilder)1 DimensionConverter (io.druid.emitter.statsd.DimensionConverter)1 StatsDMetric (io.druid.emitter.statsd.StatsDMetric)1 ISE (io.druid.java.util.common.ISE)1 DataSegment (io.druid.timeline.DataSegment)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Nullable (javax.annotation.Nullable)1 DateTime (org.joda.time.DateTime)1