use of org.apache.hadoop.metrics2.sink.timeline.TimelineMetric in project druid by druid-io.
the class SendAllTimelineEventConverter method druidEventToTimelineMetric.
@Override
public TimelineMetric druidEventToTimelineMetric(ServiceMetricEvent serviceMetricEvent) {
ImmutableList.Builder metricNameBuilder = new ImmutableList.Builder<>();
if (!Strings.isNullOrEmpty(namespacePrefix)) {
metricNameBuilder.add(namespacePrefix);
}
metricNameBuilder.add(AmbariMetricsEmitter.sanitize(serviceMetricEvent.getService()));
ImmutableSortedSet<String> dimNames = ImmutableSortedSet.copyOf(serviceMetricEvent.getUserDims().keySet());
for (String dimName : dimNames) {
metricNameBuilder.add(AmbariMetricsEmitter.sanitize(String.valueOf(serviceMetricEvent.getUserDims().get(dimName))));
}
metricNameBuilder.add(AmbariMetricsEmitter.sanitize(serviceMetricEvent.getMetric()));
TimelineMetric metric = new TimelineMetric();
metric.setMetricName(Joiner.on(".").join(metricNameBuilder.build()));
metric.setAppId(appName);
metric.setHostName(serviceMetricEvent.getHost());
metric.setType(serviceMetricEvent.getFeed());
metric.setInstanceId(serviceMetricEvent.getService());
long ts = serviceMetricEvent.getCreatedTime().getMillis();
metric.setStartTime(ts);
metric.setTimestamp(ts);
metric.getMetricValues().put(ts, serviceMetricEvent.getValue().doubleValue());
return metric;
}
use of org.apache.hadoop.metrics2.sink.timeline.TimelineMetric 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());
}
Aggregations