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;
}
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);
}
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;
}
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);
}
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;
}
Aggregations