|
@@ -27,6 +27,7 @@ import org.apache.hadoop.metrics2.annotation.Metric;
|
|
import org.apache.hadoop.metrics2.annotation.Metrics;
|
|
import org.apache.hadoop.metrics2.annotation.Metrics;
|
|
import org.apache.hadoop.metrics2.lib.DefaultMetricsSystem;
|
|
import org.apache.hadoop.metrics2.lib.DefaultMetricsSystem;
|
|
import org.apache.hadoop.metrics2.lib.MetricsRegistry;
|
|
import org.apache.hadoop.metrics2.lib.MetricsRegistry;
|
|
|
|
+import org.apache.hadoop.metrics2.lib.MutableGaugeInt;
|
|
import org.apache.hadoop.metrics2.lib.MutableStat;
|
|
import org.apache.hadoop.metrics2.lib.MutableStat;
|
|
import org.apache.hadoop.yarn.api.records.ContainerId;
|
|
import org.apache.hadoop.yarn.api.records.ContainerId;
|
|
|
|
|
|
@@ -41,11 +42,28 @@ import static org.apache.hadoop.metrics2.lib.Interns.info;
|
|
@Metrics(context="container")
|
|
@Metrics(context="container")
|
|
public class ContainerMetrics implements MetricsSource {
|
|
public class ContainerMetrics implements MetricsSource {
|
|
|
|
|
|
|
|
+ public static final String PMEM_LIMIT_METRIC_NAME = "pMemLimit";
|
|
|
|
+ public static final String VMEM_LIMIT_METRIC_NAME = "vMemLimit";
|
|
|
|
+ public static final String VCORE_LIMIT_METRIC_NAME = "vCoreLimit";
|
|
|
|
+ public static final String PMEM_USAGE_METRIC_NAME = "pMemUsage";
|
|
|
|
+
|
|
@Metric
|
|
@Metric
|
|
public MutableStat pMemMBsStat;
|
|
public MutableStat pMemMBsStat;
|
|
|
|
|
|
|
|
+ @Metric
|
|
|
|
+ public MutableGaugeInt pMemLimitMbs;
|
|
|
|
+
|
|
|
|
+ @Metric
|
|
|
|
+ public MutableGaugeInt vMemLimitMbs;
|
|
|
|
+
|
|
|
|
+ @Metric
|
|
|
|
+ public MutableGaugeInt cpuVcores;
|
|
|
|
+
|
|
static final MetricsInfo RECORD_INFO =
|
|
static final MetricsInfo RECORD_INFO =
|
|
- info("ContainerUsage", "Resource usage by container");
|
|
|
|
|
|
+ info("ContainerResource", "Resource limit and usage by container");
|
|
|
|
+
|
|
|
|
+ public static final MetricsInfo PROCESSID_INFO =
|
|
|
|
+ info("ContainerPid", "Container Process Id");
|
|
|
|
|
|
final MetricsInfo recordInfo;
|
|
final MetricsInfo recordInfo;
|
|
final MetricsRegistry registry;
|
|
final MetricsRegistry registry;
|
|
@@ -76,7 +94,13 @@ public class ContainerMetrics implements MetricsSource {
|
|
scheduleTimerTaskIfRequired();
|
|
scheduleTimerTaskIfRequired();
|
|
|
|
|
|
this.pMemMBsStat = registry.newStat(
|
|
this.pMemMBsStat = registry.newStat(
|
|
- "pMem", "Physical memory stats", "Usage", "MBs", true);
|
|
|
|
|
|
+ PMEM_USAGE_METRIC_NAME, "Physical memory stats", "Usage", "MBs", true);
|
|
|
|
+ this.pMemLimitMbs = registry.newGauge(
|
|
|
|
+ PMEM_LIMIT_METRIC_NAME, "Physical memory limit in MBs", 0);
|
|
|
|
+ this.vMemLimitMbs = registry.newGauge(
|
|
|
|
+ VMEM_LIMIT_METRIC_NAME, "Virtual memory limit in MBs", 0);
|
|
|
|
+ this.cpuVcores = registry.newGauge(
|
|
|
|
+ VCORE_LIMIT_METRIC_NAME, "CPU limit in number of vcores", 0);
|
|
}
|
|
}
|
|
|
|
|
|
ContainerMetrics tag(MetricsInfo info, ContainerId containerId) {
|
|
ContainerMetrics tag(MetricsInfo info, ContainerId containerId) {
|
|
@@ -88,10 +112,6 @@ public class ContainerMetrics implements MetricsSource {
|
|
return RECORD_INFO.name() + "_" + containerId.toString();
|
|
return RECORD_INFO.name() + "_" + containerId.toString();
|
|
}
|
|
}
|
|
|
|
|
|
- public static ContainerMetrics forContainer(ContainerId containerId) {
|
|
|
|
- return forContainer(containerId, -1L);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
public static ContainerMetrics forContainer(
|
|
public static ContainerMetrics forContainer(
|
|
ContainerId containerId, long flushPeriodMs) {
|
|
ContainerId containerId, long flushPeriodMs) {
|
|
return forContainer(
|
|
return forContainer(
|
|
@@ -150,6 +170,16 @@ public class ContainerMetrics implements MetricsSource {
|
|
this.pMemMBsStat.add(memoryMBs);
|
|
this.pMemMBsStat.add(memoryMBs);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ public void recordProcessId(String processId) {
|
|
|
|
+ registry.tag(PROCESSID_INFO, processId);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public void recordResourceLimit(int vmemLimit, int pmemLimit, int cpuVcores) {
|
|
|
|
+ this.vMemLimitMbs.set(vmemLimit);
|
|
|
|
+ this.pMemLimitMbs.set(pmemLimit);
|
|
|
|
+ this.cpuVcores.set(cpuVcores);
|
|
|
|
+ }
|
|
|
|
+
|
|
private synchronized void scheduleTimerTaskIfRequired() {
|
|
private synchronized void scheduleTimerTaskIfRequired() {
|
|
if (flushPeriodMs > 0) {
|
|
if (flushPeriodMs > 0) {
|
|
// Lazily initialize timer
|
|
// Lazily initialize timer
|