Search in sources :

Example 1 with ProcessInfo

use of com.jezhumble.javasysmon.ProcessInfo in project gocd by gocd.

the class SubprocessLogger method logSubprocess.

private void logSubprocess() {
    final StringBuffer processDetails = new StringBuffer();
    sysMon.visitProcessTree(sysMon.currentPid(), new ProcessVisitor() {

        public boolean visit(OsProcess process, int level) {
            if (level == 1) {
                ProcessInfo processInfo = process.processInfo();
                processDetails.append(String.format("\n\tPID: %s\tname: %s\towner: %s\tcommand: %s", processInfo.getPid(), processInfo.getName(), processInfo.getOwner(), processInfo.getCommand()));
            }
            return false;
        }
    });
    if (!processDetails.toString().isEmpty()) {
        LOGGER.warn(warnMessage + processDetails);
    }
}
Also used : OsProcess(com.jezhumble.javasysmon.OsProcess) ProcessVisitor(com.jezhumble.javasysmon.ProcessVisitor) ProcessInfo(com.jezhumble.javasysmon.ProcessInfo)

Example 2 with ProcessInfo

use of com.jezhumble.javasysmon.ProcessInfo in project gocd by gocd.

the class SubprocessLoggerTest method stubSysMon.

private JavaSysMon stubSysMon() {
    final OsProcess process1 = mock(OsProcess.class);
    when(process1.processInfo()).thenReturn(new ProcessInfo(101, 100, "command-1", "name-1", "owner-1", 100, 200, 400, 800));
    final OsProcess process1a = mock(OsProcess.class);
    when(process1a.processInfo()).thenReturn(new ProcessInfo(103, 100, "command-1a", "name-1a", "owner-1", 160, 260, 460, 860));
    final OsProcess process2 = mock(OsProcess.class);
    when(process2.processInfo()).thenReturn(new ProcessInfo(102, 101, "command-2", "name-2", "owner-1", 150, 250, 450, 850));
    JavaSysMon sysMon = new JavaSysMon() {

        @Override
        public void visitProcessTree(int pid, ProcessVisitor processVisitor) {
            processVisitor.visit(process2, 2);
            processVisitor.visit(process1, 1);
            processVisitor.visit(process1a, 1);
        }

        @Override
        public int currentPid() {
            return 100;
        }
    };
    return sysMon;
}
Also used : OsProcess(com.jezhumble.javasysmon.OsProcess) JavaSysMon(com.jezhumble.javasysmon.JavaSysMon) ProcessVisitor(com.jezhumble.javasysmon.ProcessVisitor) ProcessInfo(com.jezhumble.javasysmon.ProcessInfo)

Aggregations

OsProcess (com.jezhumble.javasysmon.OsProcess)2 ProcessInfo (com.jezhumble.javasysmon.ProcessInfo)2 ProcessVisitor (com.jezhumble.javasysmon.ProcessVisitor)2 JavaSysMon (com.jezhumble.javasysmon.JavaSysMon)1