diff --git a/indexing-service/src/main/java/io/druid/indexing/overlord/ForkingTaskRunner.java b/indexing-service/src/main/java/io/druid/indexing/overlord/ForkingTaskRunner.java index 4a06bcaa1d3..5db44641bbc 100644 --- a/indexing-service/src/main/java/io/druid/indexing/overlord/ForkingTaskRunner.java +++ b/indexing-service/src/main/java/io/druid/indexing/overlord/ForkingTaskRunner.java @@ -52,7 +52,9 @@ import io.druid.indexing.common.task.Task; import io.druid.indexing.common.tasklogs.LogUtils; import io.druid.indexing.overlord.config.ForkingTaskRunnerConfig; import io.druid.indexing.worker.config.WorkerConfig; +import io.druid.query.DruidMetrics; import io.druid.server.DruidNode; +import io.druid.server.metrics.MonitorsConfig; import io.druid.tasklogs.TaskLogPusher; import io.druid.tasklogs.TaskLogStreamer; import org.apache.commons.io.FileUtils; @@ -297,6 +299,24 @@ public class ForkingTaskRunner implements TaskRunner, TaskLogStreamer } } + // Add dataSource and taskId for metrics + command.add( + String.format( + "-D%s%s=%s", + MonitorsConfig.METRIC_DIMENSION_PREFIX, + DruidMetrics.DATASOURCE, + task.getDataSource() + ) + ); + command.add( + String.format( + "-D%s%s=%s", + MonitorsConfig.METRIC_DIMENSION_PREFIX, + DruidMetrics.TASK_ID, + task.getId() + ) + ); + command.add(String.format("-Ddruid.host=%s", childHost)); command.add(String.format("-Ddruid.port=%d", childPort)); diff --git a/processing/src/main/java/io/druid/query/DruidMetrics.java b/processing/src/main/java/io/druid/query/DruidMetrics.java index 58deed81f2d..568835e4315 100644 --- a/processing/src/main/java/io/druid/query/DruidMetrics.java +++ b/processing/src/main/java/io/druid/query/DruidMetrics.java @@ -36,6 +36,7 @@ public class DruidMetrics public final static String TYPE = "type"; public final static String INTERVAL = "interval"; public final static String ID = "id"; + public final static String TASK_ID = "taskId"; public final static String STATUS = "status"; // task metrics diff --git a/server/src/main/java/io/druid/server/metrics/MetricsModule.java b/server/src/main/java/io/druid/server/metrics/MetricsModule.java index 2d80a760d2e..b4b43848e6c 100644 --- a/server/src/main/java/io/druid/server/metrics/MetricsModule.java +++ b/server/src/main/java/io/druid/server/metrics/MetricsModule.java @@ -28,15 +28,21 @@ import com.google.inject.Provides; import com.google.inject.name.Names; import com.metamx.common.logger.Logger; import com.metamx.emitter.service.ServiceEmitter; +import com.metamx.metrics.JvmCpuMonitor; +import com.metamx.metrics.JvmMonitor; import com.metamx.metrics.Monitor; import com.metamx.metrics.MonitorScheduler; +import com.metamx.metrics.SysMonitor; import io.druid.concurrent.Execs; import io.druid.guice.DruidBinders; import io.druid.guice.JsonConfigProvider; import io.druid.guice.LazySingleton; import io.druid.guice.ManageLifecycle; +import java.util.HashMap; import java.util.List; +import java.util.Map; +import java.util.Properties; import java.util.Set; /** @@ -95,4 +101,40 @@ public class MetricsModule implements Module monitors ); } + + @Provides + @ManageLifecycle + public JvmMonitor getJvmMonitor(Properties props) + { + return new JvmMonitor(getDimensions(props)); + } + + @Provides + @ManageLifecycle + public JvmCpuMonitor getJvmCpuMonitor(Properties props) + { + return new JvmCpuMonitor(getDimensions(props)); + } + + @Provides + @ManageLifecycle + public SysMonitor getSysMonitor(Properties props) + { + return new SysMonitor(getDimensions(props)); + } + + private Map getDimensions(Properties props) + { + Map dimensions = new HashMap<>(); + for (String property : props.stringPropertyNames()) { + if (property.startsWith(MonitorsConfig.METRIC_DIMENSION_PREFIX)) { + dimensions.put( + property.substring(MonitorsConfig.METRIC_DIMENSION_PREFIX.length()), + new String[]{props.getProperty(property)} + ); + } + } + return dimensions; + } + } diff --git a/server/src/main/java/io/druid/server/metrics/MonitorsConfig.java b/server/src/main/java/io/druid/server/metrics/MonitorsConfig.java index 53f8559ee69..11bddf4f8a9 100644 --- a/server/src/main/java/io/druid/server/metrics/MonitorsConfig.java +++ b/server/src/main/java/io/druid/server/metrics/MonitorsConfig.java @@ -28,6 +28,8 @@ import java.util.List; */ public class MonitorsConfig { + public final static String METRIC_DIMENSION_PREFIX = "druid.metrics.emitter.dimension."; + @JsonProperty("monitors") @NotNull private List> monitors = Lists.newArrayList();