/** * Constructor for {@link ProcessInfoQuery} given an collection of process information that represents the processes * currently running. Think of the <code>processes</code> data as coming from part of the output you see in the * typical UNIX "ps" command. * * @param processes * * @see NativeSystemInfo#getAllProcesses() */ public ProcessInfoQuery(List<ProcessInfo> processes) { this.allProcesses = new HashMap<Long, ProcessInfo>(processes.size()); for (ProcessInfo process : processes) { this.allProcesses.put(process.getPid(), process); } }
/** * Constructor for {@link ProcessInfoQuery} given an collection of process information that represents the processes * currently running. Think of the <code>processes</code> data as coming from part of the output you see in the * typical UNIX "ps" command. * * @param processes * * @see NativeSystemInfo#getAllProcesses() */ public ProcessInfoQuery(List<ProcessInfo> processes) { this.allProcesses = new HashMap<Long, ProcessInfo>(processes.size()); for (ProcessInfo process : processes) { this.allProcesses.put(process.getPid(), process); } }
@Override public String toString() { StringBuilder s = new StringBuilder("process: "); s.append("pid=["); s.append(getPid()); s.append("], name=["); s.append((!getName().equals(UNKNOWN_PROCESS_NAME)) ? getName() : getBaseName()); s.append("], ppid=["); try { s.append(priorSnaphot().getParentPid()); } catch (Exception e) { s.append(e); } s.append("]"); return s.toString(); }
@Override public String toString() { StringBuilder s = new StringBuilder("process: "); s.append("pid=["); s.append(getPid()); s.append("], name=["); s.append((!getName().equals(UNKNOWN_PROCESS_NAME)) ? getName() : getBaseName()); s.append("], ppid=["); try { s.append(priorSnaphot().getParentPid()); } catch (Exception e) { s.append(e); } s.append("]"); return s.toString(); }
private static VirtualMachine attachToVirtualMachine(ProcessInfo process) throws AttachNotSupportedException, IOException { VirtualMachine vm = null; List<VirtualMachineDescriptor> vmDescriptors = VirtualMachine.list(); for (VirtualMachineDescriptor vmDescriptor : vmDescriptors) { if (Long.valueOf(vmDescriptor.id()) == process.getPid()) { String vmUserName = process.getCredentialsName().getUser(); String agentUserName = System.getProperty("user.name"); if (vmUserName.equals(agentUserName)) { LOG.debug("Attaching to JVM for java process with PID [" + process.getPid() + "]..."); vm = VirtualMachine.attach(vmDescriptor); LOG.debug("Attached to JVM [" + vm + "]."); } else { LOG.debug("Cannot attach to JVM for java process with PID [" + process.getPid() + "], because it is running as a different user (" + vmUserName + ") than the user the Agent is running as (" + agentUserName + ")."); } break; } } return vm; }
protected String getJavaVersion(ProcessInfo process, JMXServiceURL jmxServiceURL) { JMXConnector jmxConnector = null; try { jmxConnector = connect(jmxServiceURL); return getJavaVersion(jmxConnector); } catch (SecurityException e) { log.warn("Unable to to authenticate to JMX service URL [" + jmxServiceURL + "]: " + e.getMessage()); } catch (IOException e) { log.error("Failed to connect to JMX service URL [" + jmxServiceURL + "].", e); } catch (Exception e) { log.error("Failed to determine JVM version for process [" + process.getPid() + "] with command line [" + Arrays.asList(process.getCommandLine()) + "].", e); } finally { close(jmxConnector); } // TODO: We could exec "java -version" here. return null; }
private JvmResourceKey buildResourceKey(ProcessInfo process, Integer jmxRemotingPort) { JvmResourceKey key; String mainClassName = getJavaMainClassName(process); String keyString = getSystemPropertyValue(process, SYSPROP_RHQ_RESOURCE_KEY); if (keyString != null && !keyString.equals("")) { log.debug("Using explicitly specified Resource key: [" + keyString + "]..."); key = JvmResourceKey.fromExplicitValue(mainClassName, keyString); } else { if (jmxRemotingPort != null) { log.debug("Using JMX remoting port [" + jmxRemotingPort + "] as Resource key..."); key = JvmResourceKey.fromJmxRemotingPort(mainClassName, jmxRemotingPort); } else { log.debug("Process [" + process.getPid() + "] with command line [" + Arrays.asList(process.getCommandLine()) + "] cannot be discovered, because it does not specify either of the following system properties: " + "-D" + SYSPROP_JMXREMOTE_PORT + "=12345, -D" + SYSPROP_RHQ_RESOURCE_KEY + "=UNIQUE_KEY"); key = null; } } return key; }
operand1 = arg; if (op.doOperation(operand1, operand2)) { matches.put(process.getPid(), process); break; // we got a match, don't bother looking at more args matches.put(process.getPid(), process); matches.put(process.getPid(), process); break; // no need to continue, we've got the match we are looking for
operand1 = arg; if (op.doOperation(operand1, operand2)) { matches.put(process.getPid(), process); break; // we got a match, don't bother looking at more args matches.put(process.getPid(), process); matches.put(process.getPid(), process); break; // no need to continue, we've got the match we are looking for
operand2 = criteria.getValue(); } else if (attribute.getAttributeValue().equals(Attribute.ProcessCategoryAttributes.pid.toString())) { operand1 = (processToMatch != null) ? Long.toString(processToMatch.getPid()) : ""; operand2 = criteria.getValue(); } else if (attribute.getAttributeValue().equals(Attribute.ProcessCategoryAttributes.pidfile.toString())) { operand1 = (processToMatch != null) ? String.valueOf(processToMatch.getPid()) : null; operand2 = pidfileContentsCache; } else { matches.put(process.getPid(), process);
operand2 = criteria.getValue(); } else if (attribute.getAttributeValue().equals(Attribute.ProcessCategoryAttributes.pid.toString())) { operand1 = (processToMatch != null) ? Long.toString(processToMatch.getPid()) : ""; operand2 = criteria.getValue(); } else if (attribute.getAttributeValue().equals(Attribute.ProcessCategoryAttributes.pidfile.toString())) { operand1 = (processToMatch != null) ? String.valueOf(processToMatch.getPid()) : null; operand2 = pidfileContentsCache; } else { matches.put(process.getPid(), process);