Search in sources :

Example 1 with TimelineMetric

use of org.apache.hadoop.metrics2.sink.timeline.TimelineMetric in project druid by druid-io.

the class WhiteListBasedDruidToTimelineEventConverter method druidEventToTimelineMetric.

/**
   * @param serviceMetricEvent druid metric event to convert
   *
   * @return <tt>null</tt> if the event is not white listed, otherwise return {@link TimelineMetric}
   * <p>
   * The metric name of the ambari timeline metric event is:
   * <namespacePrefix>.<druid service name>.<white-listed dimensions>.<metric>
   * <p/>
   * The order of the dimension is the order returned by {@code getOrderedDimValues()}
   * Note that this name will be sanitized by replacing all the `.` or space by `_` {@link AmbariMetricsEmitter#sanitize(String)}
   * </p>
   */
@Override
public TimelineMetric druidEventToTimelineMetric(ServiceMetricEvent serviceMetricEvent) {
    if (!this.isInWhiteList(serviceMetricEvent)) {
        return null;
    }
    final ImmutableList.Builder<String> metricNameBuilder = new ImmutableList.Builder<>();
    if (!Strings.isNullOrEmpty(namespacePrefix)) {
        metricNameBuilder.add(namespacePrefix);
    }
    metricNameBuilder.add(AmbariMetricsEmitter.sanitize(serviceMetricEvent.getService()));
    metricNameBuilder.addAll(this.getOrderedDimValues(serviceMetricEvent));
    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 2 with TimelineMetric

use of org.apache.hadoop.metrics2.sink.timeline.TimelineMetric in project druid by druid-io.

the class WhiteListBasedDruidToTimelineEventConverterTest method testGetName.

@Test
@Parameters
public void testGetName(ServiceMetricEvent serviceMetricEvent, String expectedPath) {
    TimelineMetric metric = defaultWhiteListBasedDruidToTimelineEventConverter.druidEventToTimelineMetric(serviceMetricEvent);
    String path = null;
    if (metric != null) {
        path = metric.getMetricName();
    }
    Assert.assertEquals(expectedPath, path);
}
Also used : TimelineMetric(org.apache.hadoop.metrics2.sink.timeline.TimelineMetric) Parameters(junitparams.Parameters) Test(org.junit.Test)

Example 3 with TimelineMetric

use of org.apache.hadoop.metrics2.sink.timeline.TimelineMetric in project druid by druid-io.

the class WhiteListBasedDruidToTimelineEventConverter method druidEventToTimelineMetric.

/**
 * @param serviceMetricEvent druid metric event to convert
 *
 * @return <tt>null</tt> if the event is not white listed, otherwise return {@link TimelineMetric}
 * <p>
 * The metric name of the ambari timeline metric event is:
 * <namespacePrefix>.<druid service name>.<white-listed dimensions>.<metric>
 * <p/>
 * The order of the dimension is the order returned by {@code getOrderedDimValues()}
 * Note that this name will be sanitized by replacing all the `.` or space by `_` {@link AmbariMetricsEmitter#sanitize(String)}
 * </p>
 */
@Override
public TimelineMetric druidEventToTimelineMetric(ServiceMetricEvent serviceMetricEvent) {
    if (!this.isInWhiteList(serviceMetricEvent)) {
        return null;
    }
    final ImmutableList.Builder<String> metricNameBuilder = new ImmutableList.Builder<>();
    if (!Strings.isNullOrEmpty(namespacePrefix)) {
        metricNameBuilder.add(namespacePrefix);
    }
    metricNameBuilder.add(AmbariMetricsEmitter.sanitize(serviceMetricEvent.getService()));
    metricNameBuilder.addAll(this.getOrderedDimValues(serviceMetricEvent));
    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 4 with TimelineMetric

use of org.apache.hadoop.metrics2.sink.timeline.TimelineMetric in project druid by druid-io.

the class WhiteListBasedDruidToTimelineEventConverterTest method testGetName.

@Test
@Parameters
public void testGetName(ServiceMetricEvent serviceMetricEvent, String expectedPath) {
    TimelineMetric metric = defaultWhiteListBasedDruidToTimelineEventConverter.druidEventToTimelineMetric(serviceMetricEvent);
    String path = null;
    if (metric != null) {
        path = metric.getMetricName();
    }
    Assert.assertEquals(expectedPath, path);
}
Also used : TimelineMetric(org.apache.hadoop.metrics2.sink.timeline.TimelineMetric) Parameters(junitparams.Parameters) Test(org.junit.Test)

Example 5 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)

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