getObjectName method for SigarProcess
This commit is contained in:
parent
27a8d74436
commit
2bc3a6ce2a
|
@ -46,8 +46,8 @@ import org.hyperic.sigar.SigarProxyCache;
|
|||
*/
|
||||
public abstract class AbstractMBean implements DynamicMBean, MBeanRegistration {
|
||||
|
||||
protected static final String MBEAN_DOMAIN = SigarInvokerJMX.DOMAIN_NAME;
|
||||
protected static final String MBEAN_ATTR_TYPE = SigarInvokerJMX.PROP_TYPE;
|
||||
public static final String MBEAN_DOMAIN = SigarInvokerJMX.DOMAIN_NAME;
|
||||
public static final String MBEAN_ATTR_TYPE = SigarInvokerJMX.PROP_TYPE;
|
||||
|
||||
protected static final short CACHED_30SEC = 0;
|
||||
|
||||
|
|
|
@ -21,6 +21,7 @@ package org.hyperic.sigar.jmx;
|
|||
import org.hyperic.sigar.ProcCpu;
|
||||
import org.hyperic.sigar.ProcFd;
|
||||
import org.hyperic.sigar.ProcMem;
|
||||
import org.hyperic.sigar.ProcUtil;
|
||||
import org.hyperic.sigar.Sigar;
|
||||
import org.hyperic.sigar.SigarException;
|
||||
import org.hyperic.sigar.SigarProxy;
|
||||
|
@ -82,6 +83,23 @@ public class SigarProcess implements SigarProcessMBean {
|
|||
}
|
||||
}
|
||||
|
||||
public String getObjectName() throws SigarException {
|
||||
long pid = getPid();
|
||||
String name = this.sigar.getProcState(pid).getName();
|
||||
String cls = "unknown";
|
||||
if (name.startsWith("java")) {
|
||||
try {
|
||||
cls = ProcUtil.getJavaMainClass(this.sigar, pid);
|
||||
} catch (SigarException e) {}
|
||||
} //else XXX
|
||||
return
|
||||
AbstractMBean.MBEAN_DOMAIN + ":" +
|
||||
AbstractMBean.MBEAN_ATTR_TYPE + "=" + "Process" + "," +
|
||||
"Name" + "=" + name + "," +
|
||||
"Class" + "=" + cls + "," +
|
||||
"Pid" + "=" + pid;
|
||||
}
|
||||
|
||||
public long getPid() {
|
||||
if (this.pid < 0) {
|
||||
return this.sigar.getPid();
|
||||
|
|
Loading…
Reference in New Issue