检测YARN何时杀死容器

时间:2017-12-12 16:16:25

标签: hadoop mapreduce yarn hadoop2

我在Java上有MR2工作。 是否有可能在容器内检测和处理容器杀死? 我试过使用像

这样的代码
Runtime.getRuntime().addShutdownHook(new Hooker(this));

但是没有找到Hooker类实例的日志。 也许有可能为这个容器获取java堆转储?

杀死理由

Container [pid=35696,containerID=container_1509737408754_96482_01_000384] is running beyond physical memory limits. 
Current usage: 2.0 GB of 2 GB physical memory used; 3.6 GB of 4.2 GB virtual memory used. Killing container. Dump of the process-tree for container_1509737408754_96482_01_000384 : |- PID PPID PGRPID SESSID CMD_NAME USER_MODE_TIME(MILLIS) SYSTEM_TIME(MILLIS) VMEM_USAGE(BYTES) RSSMEM_USAGE(PAGES) FULL_CMD_LINE |- 35696 35694 35696 35696 (bash)

由于

1 个答案:

答案 0 :(得分:0)

您可以使用子进程,使用以下代码并添加过滤器以检测纱线杀死。

public class YarnLog {
//
public static void getYarnLog(String appid) throws IOException {
    BufferedReader br = null;
    try {
        Process p = Runtime.getRuntime().exec(String.format("yarn logs -applicationId %s", appid));
        br = new BufferedReader(new InputStreamReader(p.getInputStream()));
        String line;
        while((line = br.readLine()) != null) {
            System.out.println(line);
        }
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        if(br != null) {
            br.close();
        }
    }
}

}

相关问题