Search in sources :

Example 6 with TimelineMetric

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;
}
Also used : TimelineMetric(org.apache.hadoop.metrics2.sink.timeline.TimelineMetric) ImmutableList(com.google.common.collect.ImmutableList)

Example 7 with TimelineMetric

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());
}
Also used : TimelineMetric(org.apache.hadoop.metrics2.sink.timeline.TimelineMetric) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) FileOutputStream(java.io.FileOutputStream) ServiceMetricEvent(org.apache.druid.java.util.emitter.service.ServiceMetricEvent) DefaultObjectMapper(org.apache.druid.jackson.DefaultObjectMapper) File(java.io.File) Test(org.junit.Test)

Aggregations

TimelineMetric (org.apache.hadoop.metrics2.sink.timeline.TimelineMetric)7 ImmutableList (com.google.common.collect.ImmutableList)4 Test (org.junit.Test)3 Parameters (junitparams.Parameters)2 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 OutputStream (java.io.OutputStream)1 DefaultObjectMapper (org.apache.druid.jackson.DefaultObjectMapper)1 ServiceMetricEvent (org.apache.druid.java.util.emitter.service.ServiceMetricEvent)1