use of org.apache.druid.java.util.emitter.service.ServiceMetricEvent in project druid by druid-io.
the class DropwizardEmitter method emit.
@Override
public void emit(Event event) {
synchronized (started) {
if (!started.get()) {
throw new RejectedExecutionException("Dropwizard emitter Service not started.");
}
}
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<>();
LinkedHashMap<String, String> dims = new LinkedHashMap<>();
final DropwizardMetricSpec metricSpec = converter.addFilteredUserDims(service, metric, userDims, dims);
if (metricSpec != null) {
if (config.getPrefix() != null) {
nameBuilder.add(config.getPrefix());
}
nameBuilder.add(StringUtils.format("metric=%s", metric));
nameBuilder.add(StringUtils.format("service=%s", service));
if (config.getIncludeHost()) {
nameBuilder.add(StringUtils.format("hostname=%s", host));
}
dims.forEach((key, value1) -> nameBuilder.add(StringUtils.format("%s=%s", key, value1)));
String fullName = StringUtils.replaceChar(Joiner.on(",").join(nameBuilder.build()), '/', ".");
updateMetric(fullName, value, metricSpec);
} else {
log.debug("Service=[%s], Metric=[%s] has no mapping", service, metric);
}
} else if (event instanceof AlertEvent) {
for (Emitter emitter : alertEmitters) {
emitter.emit(event);
}
} else {
throw new ISE("unknown event type [%s]", event.getClass());
}
}
use of org.apache.druid.java.util.emitter.service.ServiceMetricEvent in project druid by druid-io.
the class WhiteListBasedDruidToTimelineEventConverterTest method testWhiteListedStringArrayDimension.
@Test
public void testWhiteListedStringArrayDimension() throws IOException {
File mapFile = File.createTempFile("testing-" + System.nanoTime(), ".json");
mapFile.deleteOnExit();
try (OutputStream outputStream = new FileOutputStream(mapFile)) {
IOUtils.copyLarge(getClass().getResourceAsStream("/testWhiteListedStringArrayDimension.json"), outputStream);
}
WhiteListBasedDruidToTimelineEventConverter converter = new WhiteListBasedDruidToTimelineEventConverter(prefix, "druid", mapFile.getAbsolutePath(), new DefaultObjectMapper());
ServiceMetricEvent event = new ServiceMetricEvent.Builder().setDimension("gcName", new String[] { "g1" }).build(createdTime, "jvm/gc/cpu", 10).build(serviceName, hostname);
TimelineMetric metric = converter.druidEventToTimelineMetric(event);
Assert.assertNotNull(metric);
Assert.assertEquals(defaultNamespace + ".g1.jvm/gc/cpu", metric.getMetricName());
}
use of org.apache.druid.java.util.emitter.service.ServiceMetricEvent in project druid by druid-io.
the class WhiteListBasedConverterTest method testWhiteListedStringArrayDimension.
@Test
public void testWhiteListedStringArrayDimension() throws IOException {
File mapFile = File.createTempFile("testing-" + System.nanoTime(), ".json");
mapFile.deleteOnExit();
try (OutputStream outputStream = new FileOutputStream(mapFile)) {
IOUtils.copyLarge(getClass().getResourceAsStream("/testWhiteListedStringArrayDimension.json"), outputStream);
}
WhiteListBasedConverter converter = new WhiteListBasedConverter(prefix, false, false, false, mapFile.getAbsolutePath(), new DefaultObjectMapper());
ServiceMetricEvent event = new ServiceMetricEvent.Builder().setDimension("gcName", new String[] { "g1" }).build(createdTime, "jvm/gc/cpu", 10).build(serviceName, hostname);
GraphiteEvent graphiteEvent = converter.druidEventToGraphite(event);
Assert.assertNotNull(graphiteEvent);
Assert.assertEquals(defaultNamespace + ".g1.jvm/gc/cpu", graphiteEvent.getEventPath());
}
use of org.apache.druid.java.util.emitter.service.ServiceMetricEvent in project druid by druid-io.
the class MetricsEmittingQueryProcessingPoolTest method testPrioritizedExecutorDelegate.
@Test
public void testPrioritizedExecutorDelegate() {
PrioritizedExecutorService service = Mockito.mock(PrioritizedExecutorService.class);
Mockito.when(service.getQueueSize()).thenReturn(10);
ExecutorServiceMonitor monitor = new ExecutorServiceMonitor();
List<Event> events = new ArrayList<>();
MetricsEmittingQueryProcessingPool processingPool = new MetricsEmittingQueryProcessingPool(service, monitor);
Assert.assertSame(service, processingPool.delegate());
ServiceEmitter serviceEmitter = new ServiceEmitter("service", "host", Mockito.mock(Emitter.class)) {
@Override
public void emit(Event event) {
events.add(event);
}
};
monitor.doMonitor(serviceEmitter);
Assert.assertEquals(1, events.size());
Assert.assertEquals(((ServiceMetricEvent) (events.get(0))).getMetric(), "segment/scan/pending");
Assert.assertEquals(((ServiceMetricEvent) (events.get(0))).getValue(), 10);
}
use of org.apache.druid.java.util.emitter.service.ServiceMetricEvent in project druid by druid-io.
the class JettyServerModuleTest method testJettyServerModule.
@Test
public void testJettyServerModule() {
List<Event> events = new ArrayList<>();
ServiceEmitter serviceEmitter = new ServiceEmitter("service", "host", Mockito.mock(Emitter.class)) {
@Override
public void emit(Event event) {
events.add(event);
}
};
QueuedThreadPool jettyServerThreadPool = Mockito.mock(QueuedThreadPool.class);
JettyServerModule.setJettyServerThreadPool(jettyServerThreadPool);
Mockito.when(jettyServerThreadPool.getThreads()).thenReturn(100);
Mockito.when(jettyServerThreadPool.getIdleThreads()).thenReturn(40);
Mockito.when(jettyServerThreadPool.isLowOnThreads()).thenReturn(true);
Mockito.when(jettyServerThreadPool.getMinThreads()).thenReturn(30);
Mockito.when(jettyServerThreadPool.getMaxThreads()).thenReturn(100);
Mockito.when(jettyServerThreadPool.getQueueSize()).thenReturn(50);
Mockito.when(jettyServerThreadPool.getBusyThreads()).thenReturn(60);
JettyServerModule.JettyMonitor jettyMonitor = new JettyServerModule.JettyMonitor("ds", "t0");
jettyMonitor.doMonitor(serviceEmitter);
Assert.assertEquals(8, events.size());
List<Pair<String, Number>> expectedEvents = Arrays.asList(new Pair<>("jetty/numOpenConnections", 0), new Pair<>("jetty/threadPool/total", 100), new Pair<>("jetty/threadPool/idle", 40), new Pair<>("jetty/threadPool/isLowOnThreads", 1), new Pair<>("jetty/threadPool/min", 30), new Pair<>("jetty/threadPool/max", 100), new Pair<>("jetty/threadPool/queueSize", 50), new Pair<>("jetty/threadPool/busy", 60));
for (int i = 0; i < expectedEvents.size(); i++) {
Pair<String, Number> expected = expectedEvents.get(i);
ServiceMetricEvent actual = (ServiceMetricEvent) (events.get(i));
Assert.assertEquals(expected.lhs, actual.getMetric());
Assert.assertEquals(expected.rhs, actual.getValue());
}
}
Aggregations