fixed formatting (tabs to spaces, version from 1.4 to 1.5, general formatting)

added MBean for "LoadAverage"
This commit is contained in:
Bjoern Martin 2007-05-01 20:26:42 +00:00
parent 3471b84099
commit 6662294a7f
8 changed files with 1825 additions and 1569 deletions

View File

@ -43,7 +43,7 @@ import org.hyperic.sigar.SigarProxyCache;
* implement subset of them. * implement subset of them.
* *
* @author Bjoern Martin * @author Bjoern Martin
* @since 1.4 (2007-04) * @since 1.5
*/ */
public abstract class AbstractMBean implements DynamicMBean, MBeanRegistration { public abstract class AbstractMBean implements DynamicMBean, MBeanRegistration {
@ -128,18 +128,15 @@ public abstract class AbstractMBean implements DynamicMBean, MBeanRegistration {
} else if (cacheMode == CACHED_500MS) { } else if (cacheMode == CACHED_500MS) {
// 500ms cached version (for 1/sec queries) // 500ms cached version (for 1/sec queries)
this.sigar = SigarProxyCache.newInstance(this.sigarImpl, this.sigar = SigarProxyCache.newInstance(this.sigarImpl, 500);
500);
} else if (cacheMode == CACHED_5SEC) { } else if (cacheMode == CACHED_5SEC) {
// 5sec cached version (for avg'd queries) // 5sec cached version (for avg'd queries)
this.sigar = SigarProxyCache.newInstance(this.sigarImpl, this.sigar = SigarProxyCache.newInstance(this.sigarImpl, 5000);
5000);
} else /* if (cacheMode == CACHED_30SEC) */{ } else /* if (cacheMode == CACHED_30SEC) */{
// 30sec (default) cached version (for info and long term queries) // 30sec (default) cached version (for info and long term queries)
this.sigar = SigarProxyCache.newInstance(this.sigarImpl, this.sigar = SigarProxyCache.newInstance(this.sigarImpl, 30000);
30000);
} }
} }
@ -216,8 +213,6 @@ public abstract class AbstractMBean implements DynamicMBean, MBeanRegistration {
return result; return result;
} }
// ------- // -------
// Implementation of the MBeanRegistration interface // Implementation of the MBeanRegistration interface
// ------- // -------
@ -231,7 +226,8 @@ public abstract class AbstractMBean implements DynamicMBean, MBeanRegistration {
* *
* @see MBeanRegistration#preRegister(MBeanServer, ObjectName) * @see MBeanRegistration#preRegister(MBeanServer, ObjectName)
*/ */
public ObjectName preRegister(MBeanServer server, ObjectName name) throws Exception { public ObjectName preRegister(MBeanServer server, ObjectName name)
throws Exception {
this.mbeanServer = server; this.mbeanServer = server;
return new ObjectName(getObjectName()); return new ObjectName(getObjectName());
} }

View File

@ -30,11 +30,11 @@ import org.hyperic.sigar.Sigar;
import org.hyperic.sigar.SigarException; import org.hyperic.sigar.SigarException;
/** /**
* Sigar JMX MBean implementation for the <code>Cpu</code> information package. * Sigar JMX MBean implementation for the <code>Cpu</code> information
* Provides an OpenMBean conform implementation. * package. Provides an OpenMBean conform implementation.
* *
* @author Bjoern Martin * @author Bjoern Martin
* @since 1.4 (2007-04) * @since 1.5
*/ */
public class SigarCpu extends AbstractMBean { public class SigarCpu extends AbstractMBean {
@ -65,74 +65,54 @@ public class SigarCpu extends AbstractMBean {
private static MBeanParameterInfo MBEAN_PARAM_SIGAR; private static MBeanParameterInfo MBEAN_PARAM_SIGAR;
static { static {
MBEAN_ATTR_CPUINDEX = new MBeanAttributeInfo( MBEAN_ATTR_CPUINDEX = new MBeanAttributeInfo("CpuIndex", "int",
"CpuIndex", "int", "The index of the CPU, typically starting at 0", true, false,
"The index of the CPU, typically starting at 0", false);
true, false, false); MBEAN_ATTR_IDLE = new MBeanAttributeInfo("Idle", "long",
MBEAN_ATTR_IDLE = new MBeanAttributeInfo( "The idle time of the CPU, in [ms]", true, false, false);
"Idle", "long", MBEAN_ATTR_NICE = new MBeanAttributeInfo("Nice", "long",
"The idle time of the CPU, in [ms]", "The time of the CPU spent on nice priority, in [ms]", true,
true, false, false); false, false);
MBEAN_ATTR_NICE = new MBeanAttributeInfo( MBEAN_ATTR_SYS = new MBeanAttributeInfo("Sys", "long",
"Nice", "long", "The time of the CPU used by the system, in [ms]", true, false,
"The time of the CPU spent on nice priority, in [ms]", false);
true, false, false); MBEAN_ATTR_TOTAL = new MBeanAttributeInfo("Total", "long",
MBEAN_ATTR_SYS = new MBeanAttributeInfo( "The total time of the CPU, in [ms]", true, false, false);
"Sys", "long", MBEAN_ATTR_USER = new MBeanAttributeInfo("User", "long",
"The time of the CPU used by the system, in [ms]", "The time of the CPU used by user processes, in [ms]", true,
true, false, false); false, false);
MBEAN_ATTR_TOTAL = new MBeanAttributeInfo( MBEAN_ATTR_WAIT = new MBeanAttributeInfo("Wait", "long",
"Total", "long",
"The total time of the CPU, in [ms]",
true, false, false);
MBEAN_ATTR_USER = new MBeanAttributeInfo(
"User", "long",
"The time of the CPU used by user processes, in [ms]",
true, false, false);
MBEAN_ATTR_WAIT = new MBeanAttributeInfo(
"Wait", "long",
"The time the CPU had to wait for data to be loaded, in [ms]", "The time the CPU had to wait for data to be loaded, in [ms]",
true, false, false); true, false, false);
MBEAN_PARAM_CPUINDEX = new MBeanParameterInfo( MBEAN_PARAM_CPUINDEX = new MBeanParameterInfo("cpuIndex", "int",
"cpuIndex", "int", "The index of the CPU to read data for. Must be >= 0 "
"The index of the CPU to read data for. Must be >= 0 " + + "and not exceed the CPU count of the system");
"and not exceed the CPU count of the system"); MBEAN_PARAM_SIGAR = new MBeanParameterInfo("sigar", Sigar.class
MBEAN_PARAM_SIGAR = new MBeanParameterInfo( .getName(), "The Sigar instance to use to fetch data from");
"sigar", Sigar.class.getName(), MBEAN_CONSTR_CPUINDEX = new MBeanConstructorInfo(SigarCpu.class
"The Sigar instance to use to fetch data from"); .getName(),
MBEAN_CONSTR_CPUINDEX = new MBeanConstructorInfo( "Creates a new instance for the CPU index specified, "
SigarCpu.class.getName(), + "using a new Sigar instance to fetch the data. "
"Creates a new instance for the CPU index specified, " + + "Fails if the CPU index is out of range.",
"using a new Sigar instance to fetch the data. " + new MBeanParameterInfo[] { MBEAN_PARAM_CPUINDEX });
"Fails if the CPU index is out of range.",
new MBeanParameterInfo[]{
MBEAN_PARAM_CPUINDEX});
MBEAN_CONSTR_CPUINDEX_SIGAR = new MBeanConstructorInfo( MBEAN_CONSTR_CPUINDEX_SIGAR = new MBeanConstructorInfo(
SigarCpu.class.getName(), SigarCpu.class.getName(),
"Creates a new instance for the CPU index specified, " + "Creates a new instance for the CPU index specified, "
"using the Sigar instance specified to fetch the data. " + + "using the Sigar instance specified to fetch the data. "
"Fails if the CPU index is out of range.", + "Fails if the CPU index is out of range.",
new MBeanParameterInfo[]{ new MBeanParameterInfo[] { MBEAN_PARAM_SIGAR,
MBEAN_PARAM_SIGAR,
MBEAN_PARAM_CPUINDEX }); MBEAN_PARAM_CPUINDEX });
MBEAN_INFO = new MBeanInfo( MBEAN_INFO = new MBeanInfo(
SigarCpu.class.getName(), SigarCpu.class.getName(),
"Sigar CPU MBean. Provides raw timing data for a single " + "Sigar CPU MBean. Provides raw timing data for a single "
"CPU. The data is cached for 500ms, meaning each request " + + "CPU. The data is cached for 500ms, meaning each request "
"(and as a result each block request to all parameters) " + + "(and as a result each block request to all parameters) "
"within half a second is satisfied from the same dataset.", + "within half a second is satisfied from the same dataset.",
new MBeanAttributeInfo[]{ new MBeanAttributeInfo[] { MBEAN_ATTR_CPUINDEX,
MBEAN_ATTR_CPUINDEX, MBEAN_ATTR_IDLE, MBEAN_ATTR_NICE, MBEAN_ATTR_SYS,
MBEAN_ATTR_IDLE, MBEAN_ATTR_TOTAL, MBEAN_ATTR_USER, MBEAN_ATTR_WAIT },
MBEAN_ATTR_NICE, new MBeanConstructorInfo[] { MBEAN_CONSTR_CPUINDEX,
MBEAN_ATTR_SYS, MBEAN_CONSTR_CPUINDEX_SIGAR }, null, null);
MBEAN_ATTR_TOTAL,
MBEAN_ATTR_USER,
MBEAN_ATTR_WAIT},
new MBeanConstructorInfo[]{
MBEAN_CONSTR_CPUINDEX,
MBEAN_CONSTR_CPUINDEX_SIGAR},
null, null);
} }
@ -151,11 +131,13 @@ public class SigarCpu extends AbstractMBean {
* Creates a new instance for the CPU index specified, using a new Sigar * Creates a new instance for the CPU index specified, using a new Sigar
* instance to fetch the data. Fails if the CPU index is out of range. * instance to fetch the data. Fails if the CPU index is out of range.
* *
* @param cpuIndex The index of the CPU to read data for. Must be * @param cpuIndex
* <code>&gt;= 0</code> and not exceed the CPU count of the system. * The index of the CPU to read data for. Must be <code>&gt;= 0</code>
* and not exceed the CPU count of the system.
* *
* @throws IllegalArgumentException If the CPU index is out of range or * @throws IllegalArgumentException
* an unexpected Sigar error occurs * If the CPU index is out of range or an unexpected Sigar error
* occurs.
*/ */
public SigarCpu(int cpuIndex) throws IllegalArgumentException { public SigarCpu(int cpuIndex) throws IllegalArgumentException {
this(new Sigar(), cpuIndex); this(new Sigar(), cpuIndex);
@ -163,15 +145,19 @@ public class SigarCpu extends AbstractMBean {
/** /**
* Creates a new instance for the CPU index specified, using the Sigar * Creates a new instance for the CPU index specified, using the Sigar
* instance specified to fetch the data. Fails if the CPU index is out * instance specified to fetch the data. Fails if the CPU index is out of
* of range. * range.
* *
* @param sigar The Sigar instance to use to fetch data from * @param sigar
* @param cpuIndex The index of the CPU to read data for. Must be * The Sigar instance to use to fetch data from
* <code>&gt;= 0</code> and not exceed the CPU count of the system. * @param cpuIndex
* The index of the CPU to read data for. Must be
* <code>&gt;= 0</code> and not exceed the CPU count of the
* system.
* *
* @throws IllegalArgumentException If the CPU index is out of range or * @throws IllegalArgumentException
* an unexpected Sigar error occurs * If the CPU index is out of range or an unexpected Sigar error
* occurs
*/ */
public SigarCpu(Sigar sigar, int cpuIndex) throws IllegalArgumentException { public SigarCpu(Sigar sigar, int cpuIndex) throws IllegalArgumentException {
super(sigar, CACHED_500MS); super(sigar, CACHED_500MS);
@ -184,7 +170,8 @@ public class SigarCpu extends AbstractMBean {
int cpuCount; int cpuCount;
if ((cpuCount = sigar.getCpuList().length) < cpuIndex) if ((cpuCount = sigar.getCpuList().length) < cpuIndex)
throw new IllegalArgumentException( throw new IllegalArgumentException(
"CPU index out of range (found " + cpuCount + " CPU(s)): " + cpuIndex); "CPU index out of range (found " + cpuCount
+ " CPU(s)): " + cpuIndex);
} catch (SigarException e) { } catch (SigarException e) {
throw unexpectedError(MBEAN_TYPE, e); throw unexpectedError(MBEAN_TYPE, e);
@ -192,8 +179,8 @@ public class SigarCpu extends AbstractMBean {
// all fine // all fine
this.cpuIndex = cpuIndex; this.cpuIndex = cpuIndex;
this.objectName = SigarInvokerJMX.DOMAIN_NAME + ":" this.objectName = SigarInvokerJMX.DOMAIN_NAME + ":" + MBEAN_ATTR_TYPE
+ MBEAN_ATTR_TYPE + "=Cpu," + "=Cpu,"
+ MBEAN_ATTR_CPUINDEX.getName().substring(0, 1).toLowerCase() + MBEAN_ATTR_CPUINDEX.getName().substring(0, 1).toLowerCase()
+ MBEAN_ATTR_CPUINDEX.getName().substring(1) + "=" + cpuIndex; + MBEAN_ATTR_CPUINDEX.getName().substring(1) + "=" + cpuIndex;
} }
@ -279,14 +266,13 @@ public class SigarCpu extends AbstractMBean {
} }
} }
// ------- // -------
// Implementation of the DynamicMBean interface // Implementation of the DynamicMBean interface
// ------- // -------
/* /*
* (non-Javadoc) * (non-Javadoc)
*
* @see DynamicMBean#getAttribute(String) * @see DynamicMBean#getAttribute(String)
*/ */
public Object getAttribute(String attr) throws AttributeNotFoundException { public Object getAttribute(String attr) throws AttributeNotFoundException {
@ -319,6 +305,7 @@ public class SigarCpu extends AbstractMBean {
/* /*
* (non-Javadoc) * (non-Javadoc)
*
* @see DynamicMBean#setAttribute(Attribute) * @see DynamicMBean#setAttribute(Attribute)
*/ */
public void setAttribute(Attribute attr) throws AttributeNotFoundException { public void setAttribute(Attribute attr) throws AttributeNotFoundException {
@ -327,14 +314,18 @@ public class SigarCpu extends AbstractMBean {
/* /*
* (non-Javadoc) * (non-Javadoc)
*
* @see DynamicMBean#invoke(String, Object[], String[]) * @see DynamicMBean#invoke(String, Object[], String[])
*/ */
public Object invoke(String actionName, Object[] params, String[] signature) throws ReflectionException { public Object invoke(String actionName, Object[] params, String[] signature)
throw new ReflectionException(new NoSuchMethodException(actionName), actionName); throws ReflectionException {
throw new ReflectionException(new NoSuchMethodException(actionName),
actionName);
} }
/* /*
* (non-Javadoc) * (non-Javadoc)
*
* @see DynamicMBean#getMBeanInfo() * @see DynamicMBean#getMBeanInfo()
*/ */
public MBeanInfo getMBeanInfo() { public MBeanInfo getMBeanInfo() {

View File

@ -34,7 +34,7 @@ import org.hyperic.sigar.SigarException;
* package. Provides an OpenMBean conform implementation. * package. Provides an OpenMBean conform implementation.
* *
* @author Bjoern Martin * @author Bjoern Martin
* @since 1.4 (2007-04) * @since 1.5
*/ */
public class SigarCpuInfo extends AbstractMBean { public class SigarCpuInfo extends AbstractMBean {
@ -61,64 +61,47 @@ public class SigarCpuInfo extends AbstractMBean {
private static final MBeanParameterInfo MBEAN_PARAM_SIGAR; private static final MBeanParameterInfo MBEAN_PARAM_SIGAR;
static { static {
MBEAN_ATTR_CPUINDEX = new MBeanAttributeInfo( MBEAN_ATTR_CPUINDEX = new MBeanAttributeInfo("CpuIndex", "int",
"CpuIndex", "int", "The index of the CPU, typically starting at 0", true, false,
"The index of the CPU, typically starting at 0", false);
true, false, false); MBEAN_ATTR_CACHESIZE = new MBeanAttributeInfo("CacheSize", "long",
MBEAN_ATTR_CACHESIZE = new MBeanAttributeInfo( "The cache size of the CPU, in [byte]", true, false, false);
"CacheSize", "long", MBEAN_ATTR_MHZ = new MBeanAttributeInfo("Mhz", "int",
"The cache size of the CPU, in [byte]", "The clock speed of the CPU, in [MHz]", true, false, false);
true, false, false); MBEAN_ATTR_MODEL = new MBeanAttributeInfo("Model", "java.lang.String",
MBEAN_ATTR_MHZ = new MBeanAttributeInfo( "The CPU model reported", true, false, false);
"Mhz", "int", MBEAN_ATTR_VENDOR = new MBeanAttributeInfo("Vendor",
"The clock speed of the CPU, in [MHz]", "java.lang.String", "The CPU vendor reported", true, false,
true, false, false); false);
MBEAN_ATTR_MODEL = new MBeanAttributeInfo( MBEAN_PARAM_CPUINDEX = new MBeanParameterInfo("cpuIndex", "int",
"Model", "java.lang.String", "The index of the CPU to read data for. Must be >= 0 "
"The CPU model reported", + "and not exceed the CPU count of the system");
true, false, false); MBEAN_PARAM_SIGAR = new MBeanParameterInfo("sigar", Sigar.class
MBEAN_ATTR_VENDOR = new MBeanAttributeInfo( .getName(), "The Sigar instance to use to fetch data from");
"Vendor", "java.lang.String", MBEAN_CONSTR_CPUINDEX = new MBeanConstructorInfo(SigarCpuInfo.class
"The CPU vendor reported", .getName(),
true, false, false); "Creates a new instance for the CPU index specified, "
MBEAN_PARAM_CPUINDEX = new MBeanParameterInfo( + "using a new Sigar instance to fetch the data. "
"cpuIndex", "int", + "Fails if the CPU index is out of range.",
"The index of the CPU to read data for. Must be >= 0 " + new MBeanParameterInfo[] { MBEAN_PARAM_CPUINDEX });
"and not exceed the CPU count of the system");
MBEAN_PARAM_SIGAR = new MBeanParameterInfo(
"sigar", Sigar.class.getName(),
"The Sigar instance to use to fetch data from");
MBEAN_CONSTR_CPUINDEX = new MBeanConstructorInfo(
SigarCpuInfo.class.getName(),
"Creates a new instance for the CPU index specified, " +
"using a new Sigar instance to fetch the data. " +
"Fails if the CPU index is out of range.",
new MBeanParameterInfo[]{
MBEAN_PARAM_CPUINDEX});
MBEAN_CONSTR_CPUINDEX_SIGAR = new MBeanConstructorInfo( MBEAN_CONSTR_CPUINDEX_SIGAR = new MBeanConstructorInfo(
SigarCpuInfo.class.getName(), SigarCpuInfo.class.getName(),
"Creates a new instance for the CPU index specified, " + "Creates a new instance for the CPU index specified, "
"using the Sigar instance specified to fetch the data. " + + "using the Sigar instance specified to fetch the data. "
"Fails if the CPU index is out of range.", + "Fails if the CPU index is out of range.",
new MBeanParameterInfo[]{ new MBeanParameterInfo[] { MBEAN_PARAM_SIGAR,
MBEAN_PARAM_SIGAR,
MBEAN_PARAM_CPUINDEX }); MBEAN_PARAM_CPUINDEX });
MBEAN_INFO = new MBeanInfo( MBEAN_INFO = new MBeanInfo(
SigarCpuInfo.class.getName(), SigarCpuInfo.class.getName(),
"Sigar CPU Info MBean, provides overall information for a " + "Sigar CPU Info MBean, provides overall information for a "
"single CPU. This information only changes if, for example, " + + "single CPU. This information only changes if, for example, "
"a CPU is reducing its clock frequency or shutting down " + + "a CPU is reducing its clock frequency or shutting down "
"part of its cache. Subsequent requests are satisfied from " + + "part of its cache. Subsequent requests are satisfied from "
"within a cache that invalidates after 30 seconds.", + "within a cache that invalidates after 30 seconds.",
new MBeanAttributeInfo[]{ new MBeanAttributeInfo[] { MBEAN_ATTR_CPUINDEX,
MBEAN_ATTR_CPUINDEX, MBEAN_ATTR_CACHESIZE, MBEAN_ATTR_MHZ, MBEAN_ATTR_MODEL,
MBEAN_ATTR_CACHESIZE, MBEAN_ATTR_VENDOR }, new MBeanConstructorInfo[] {
MBEAN_ATTR_MHZ, MBEAN_CONSTR_CPUINDEX, MBEAN_CONSTR_CPUINDEX_SIGAR },
MBEAN_ATTR_MODEL,
MBEAN_ATTR_VENDOR},
new MBeanConstructorInfo[]{
MBEAN_CONSTR_CPUINDEX,
MBEAN_CONSTR_CPUINDEX_SIGAR},
null, null); null, null);
} }
@ -171,7 +154,8 @@ public class SigarCpuInfo extends AbstractMBean {
int cpuCount; int cpuCount;
if ((cpuCount = sigar.getCpuInfoList().length) < index) if ((cpuCount = sigar.getCpuInfoList().length) < index)
throw new IllegalArgumentException( throw new IllegalArgumentException(
"CPU index out of range (found " + cpuCount + " CPU(s)): " + index); "CPU index out of range (found " + cpuCount
+ " CPU(s)): " + index);
} catch (SigarException e) { } catch (SigarException e) {
throw unexpectedError(MBEAN_TYPE, e); throw unexpectedError(MBEAN_TYPE, e);
@ -179,8 +163,8 @@ public class SigarCpuInfo extends AbstractMBean {
// all fine // all fine
this.cpuIndex = index; this.cpuIndex = index;
this.objectName = SigarInvokerJMX.DOMAIN_NAME + ":" this.objectName = SigarInvokerJMX.DOMAIN_NAME + ":" + MBEAN_ATTR_TYPE
+ MBEAN_ATTR_TYPE + "=CpuInfo," + "=CpuInfo,"
+ MBEAN_ATTR_CPUINDEX.getName().substring(0, 1).toLowerCase() + MBEAN_ATTR_CPUINDEX.getName().substring(0, 1).toLowerCase()
+ MBEAN_ATTR_CPUINDEX.getName().substring(1) + "=" + cpuIndex; + MBEAN_ATTR_CPUINDEX.getName().substring(1) + "=" + cpuIndex;
} }
@ -244,8 +228,6 @@ public class SigarCpuInfo extends AbstractMBean {
} }
} }
// ------- // -------
// Implementation of the DynamicMBean interface // Implementation of the DynamicMBean interface
// ------- // -------
@ -288,8 +270,10 @@ public class SigarCpuInfo extends AbstractMBean {
* (non-Javadoc) * (non-Javadoc)
* @see DynamicMBean#invoke(String, Object[], String[]) * @see DynamicMBean#invoke(String, Object[], String[])
*/ */
public Object invoke(String actionName, Object[] params, String[] signature) throws ReflectionException { public Object invoke(String actionName, Object[] params, String[] signature)
throw new ReflectionException(new NoSuchMethodException(actionName), actionName); throws ReflectionException {
throw new ReflectionException(new NoSuchMethodException(actionName),
actionName);
} }
/* /*

View File

@ -34,7 +34,7 @@ import org.hyperic.sigar.SigarException;
* package. Provides an OpenMBean conform implementation.</p> * package. Provides an OpenMBean conform implementation.</p>
* *
* @author Bjoern Martin * @author Bjoern Martin
* @since 1.4 (2007-04) * @since 1.5
*/ */
public class SigarCpuPerc extends AbstractMBean { public class SigarCpuPerc extends AbstractMBean {
@ -65,76 +65,64 @@ public class SigarCpuPerc extends AbstractMBean {
private static MBeanParameterInfo MBEAN_PARAM_SIGAR; private static MBeanParameterInfo MBEAN_PARAM_SIGAR;
static { static {
MBEAN_ATTR_CPUINDEX = new MBeanAttributeInfo( MBEAN_ATTR_CPUINDEX = new MBeanAttributeInfo("CpuIndex", "int",
"CpuIndex", "int", "The index of the CPU, typically starting at 0", true, false,
"The index of the CPU, typically starting at 0", false);
true, false, false); MBEAN_ATTR_COMBINED = new MBeanAttributeInfo("Combined", "double",
MBEAN_ATTR_COMBINED = new MBeanAttributeInfo( "The total time of the CPU, as a fraction of 1", true, false,
"Combined", "double", false);
"The total time of the CPU, as a fraction of 1", MBEAN_ATTR_IDLE = new MBeanAttributeInfo("Idle", "double",
true, false, false); "The idle time of the CPU, as a fraction of 1", true, false,
MBEAN_ATTR_IDLE = new MBeanAttributeInfo( false);
"Idle", "double",
"The idle time of the CPU, as a fraction of 1",
true, false, false);
MBEAN_ATTR_NICE = new MBeanAttributeInfo( MBEAN_ATTR_NICE = new MBeanAttributeInfo(
"Nice", "double", "Nice",
"double",
"The time of the CPU spent on nice priority, as a fraction of 1", "The time of the CPU spent on nice priority, as a fraction of 1",
true, false, false); true, false, false);
MBEAN_ATTR_SYS = new MBeanAttributeInfo( MBEAN_ATTR_SYS = new MBeanAttributeInfo("Sys", "double",
"Sys", "double",
"The time of the CPU used by the system, as a fraction of 1", "The time of the CPU used by the system, as a fraction of 1",
true, false, false); true, false, false);
MBEAN_ATTR_USER = new MBeanAttributeInfo( MBEAN_ATTR_USER = new MBeanAttributeInfo(
"User", "double", "User",
"double",
"The time of the CPU used by user processes, as a fraction of 1", "The time of the CPU used by user processes, as a fraction of 1",
true, false, false); true, false, false);
MBEAN_ATTR_WAIT = new MBeanAttributeInfo( MBEAN_ATTR_WAIT = new MBeanAttributeInfo(
"Wait", "double", "Wait",
"double",
"The time the CPU had to wait for data to be loaded, as a fraction of 1", "The time the CPU had to wait for data to be loaded, as a fraction of 1",
true, false, false); true, false, false);
MBEAN_PARAM_CPUINDEX = new MBeanParameterInfo( MBEAN_PARAM_CPUINDEX = new MBeanParameterInfo("cpuIndex", "int",
"cpuIndex", "int", "The index of the CPU to read data for. Must be >= 0 "
"The index of the CPU to read data for. Must be >= 0 " + + "and not exceed the CPU count of the system");
"and not exceed the CPU count of the system"); MBEAN_PARAM_SIGAR = new MBeanParameterInfo("sigar", Sigar.class
MBEAN_PARAM_SIGAR = new MBeanParameterInfo( .getName(), "The Sigar instance to use to fetch data from");
"sigar", Sigar.class.getName(), MBEAN_CONSTR_CPUINDEX = new MBeanConstructorInfo(SigarCpuPerc.class
"The Sigar instance to use to fetch data from"); .getName(),
MBEAN_CONSTR_CPUINDEX = new MBeanConstructorInfo( "Creates a new instance for the CPU index specified, "
SigarCpuPerc.class.getName(), + "using a new Sigar instance to fetch the data. "
"Creates a new instance for the CPU index specified, " + + "Fails if the CPU index is out of range.",
"using a new Sigar instance to fetch the data. " + new MBeanParameterInfo[] { MBEAN_PARAM_CPUINDEX });
"Fails if the CPU index is out of range.",
new MBeanParameterInfo[]{
MBEAN_PARAM_CPUINDEX});
MBEAN_CONSTR_CPUINDEX_SIGAR = new MBeanConstructorInfo( MBEAN_CONSTR_CPUINDEX_SIGAR = new MBeanConstructorInfo(
SigarCpuPerc.class.getName(), SigarCpuPerc.class.getName(),
"Creates a new instance for the CPU index specified, " + "Creates a new instance for the CPU index specified, "
"using the Sigar instance specified to fetch the data. " + + "using the Sigar instance specified to fetch the data. "
"Fails if the CPU index is out of range.", + "Fails if the CPU index is out of range.",
new MBeanParameterInfo[]{ new MBeanParameterInfo[] { MBEAN_PARAM_SIGAR,
MBEAN_PARAM_SIGAR,
MBEAN_PARAM_CPUINDEX }); MBEAN_PARAM_CPUINDEX });
MBEAN_INFO = new MBeanInfo( MBEAN_INFO = new MBeanInfo(
SigarCpuPerc.class.getName(), SigarCpuPerc.class.getName(),
"Sigar CPU MBean. Provides percentage data for a single " + "Sigar CPU MBean. Provides percentage data for a single "
"CPU, averaged over the timeframe between the last and " + + "CPU, averaged over the timeframe between the last and "
"the current measurement point. Two measurement points " + + "the current measurement point. Two measurement points "
"can be as close as 5 seconds, meaning subsequent requests " + + "can be as close as 5 seconds, meaning subsequent requests "
"for data within 5 seconds after the last executed call " + + "for data within 5 seconds after the last executed call "
"will be satisfied from cached data.", + "will be satisfied from cached data.",
new MBeanAttributeInfo[]{ new MBeanAttributeInfo[] { MBEAN_ATTR_CPUINDEX,
MBEAN_ATTR_CPUINDEX, MBEAN_ATTR_COMBINED, MBEAN_ATTR_IDLE, MBEAN_ATTR_NICE,
MBEAN_ATTR_COMBINED, MBEAN_ATTR_SYS, MBEAN_ATTR_USER, MBEAN_ATTR_WAIT },
MBEAN_ATTR_IDLE, new MBeanConstructorInfo[] { MBEAN_CONSTR_CPUINDEX,
MBEAN_ATTR_NICE, MBEAN_CONSTR_CPUINDEX_SIGAR }, null, null);
MBEAN_ATTR_SYS,
MBEAN_ATTR_USER,
MBEAN_ATTR_WAIT},
new MBeanConstructorInfo[]{
MBEAN_CONSTR_CPUINDEX,
MBEAN_CONSTR_CPUINDEX_SIGAR},
null, null);
} }
/** /**
@ -194,8 +182,8 @@ public class SigarCpuPerc extends AbstractMBean {
// all fine // all fine
this.cpuIndex = index; this.cpuIndex = index;
this.objectName = SigarInvokerJMX.DOMAIN_NAME + ":" this.objectName = SigarInvokerJMX.DOMAIN_NAME + ":" + MBEAN_ATTR_TYPE
+ MBEAN_ATTR_TYPE + "=CpuPerc," + "=CpuPerc,"
+ MBEAN_ATTR_CPUINDEX.getName().substring(0, 1).toLowerCase() + MBEAN_ATTR_CPUINDEX.getName().substring(0, 1).toLowerCase()
+ MBEAN_ATTR_CPUINDEX.getName().substring(1) + "=" + cpuIndex; + MBEAN_ATTR_CPUINDEX.getName().substring(1) + "=" + cpuIndex;
} }
@ -281,8 +269,6 @@ public class SigarCpuPerc extends AbstractMBean {
} }
} }
// ------- // -------
// Implementation of the DynamicMBean interface // Implementation of the DynamicMBean interface
// ------- // -------
@ -331,8 +317,10 @@ public class SigarCpuPerc extends AbstractMBean {
* (non-Javadoc) * (non-Javadoc)
* @see DynamicMBean#invoke(String, Object[], String[]) * @see DynamicMBean#invoke(String, Object[], String[])
*/ */
public Object invoke(String actionName, Object[] params, String[] signature) throws ReflectionException { public Object invoke(String actionName, Object[] params, String[] signature)
throw new ReflectionException(new NoSuchMethodException(actionName), actionName); throws ReflectionException {
throw new ReflectionException(new NoSuchMethodException(actionName),
actionName);
} }
/* /*

View File

@ -0,0 +1,263 @@
/*
* Copyright (C) [2004, 2005, 2006, 2007], Hyperic, Inc.
* This file is part of SIGAR.
*
* SIGAR is free software; you can redistribute it and/or modify
* it under the terms version 2 of the GNU General Public License as
* published by the Free Software Foundation. This program is distributed
* in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
* even the implied warranty of MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA.
*/
package org.hyperic.sigar.jmx;
import javax.management.Attribute;
import javax.management.AttributeNotFoundException;
import javax.management.MBeanAttributeInfo;
import javax.management.MBeanConstructorInfo;
import javax.management.MBeanInfo;
import javax.management.MBeanParameterInfo;
import javax.management.ReflectionException;
import org.hyperic.sigar.Sigar;
import org.hyperic.sigar.SigarException;
import org.hyperic.sigar.SigarNotImplementedException;
/**
* Sigar JMX MBean implementation for the <code>LoadAverage</code> information
* package. Provides an OpenMBean conform implementation.
*
* @author Bjoern Martin
* @since 1.5
*/
public class SigarLoadAverage extends AbstractMBean {
private static final String MBEAN_TYPE = "LoadAverage";
/**
* Returned if {@link Sigar#getLoadAverage()}} is detected to be not
* implemented on the platform.
*
* @see #notImplemented
*/
private static final double NOT_IMPLEMENTED_LOAD_VALUE = -1.0d;
private static final MBeanInfo MBEAN_INFO;
private static final MBeanAttributeInfo MBEAN_ATTR_LAST1MIN;
private static final MBeanAttributeInfo MBEAN_ATTR_LAST5MIN;
private static final MBeanAttributeInfo MBEAN_ATTR_LAST15MIN;
private static final MBeanConstructorInfo MBEAN_CONSTR_SIGAR;
private static MBeanParameterInfo MBEAN_PARAM_SIGAR;
static {
MBEAN_ATTR_LAST1MIN = new MBeanAttributeInfo(
"LastMinute",
"double",
"The load average in the last minute, as a fraction of 1, or "
+ "-1.0 if the load cannot be determined on this platform",
true, false, false);
MBEAN_ATTR_LAST5MIN = new MBeanAttributeInfo(
"LastFiveMinutes",
"double",
"The load average over the last five minutes, as a fraction "
+ "of 1, or -1.0 if the load cannot be determined on this platform",
true, false, false);
MBEAN_ATTR_LAST15MIN = new MBeanAttributeInfo(
"Last15Minutes",
"double",
"The load average over the last 15 minutes, as a fraction of "
+ "1, or -1.0 if the load cannot be determined on this platform",
true, false, false);
MBEAN_PARAM_SIGAR = new MBeanParameterInfo("sigar", Sigar.class
.getName(), "The Sigar instance to use to fetch data from");
MBEAN_CONSTR_SIGAR = new MBeanConstructorInfo(
SigarLoadAverage.class.getName(),
"Creates a new instance, using the Sigar instance specified "
+ "to fetch the data. Fails if the CPU index is out of range.",
new MBeanParameterInfo[] { MBEAN_PARAM_SIGAR });
MBEAN_INFO = new MBeanInfo(
SigarLoadAverage.class.getName(),
"Sigar load average MBean. Provides load averages of the "
+ "system over the last one, five and 15 minutes. Due to the "
+ "long term character of that information, the fetch is done "
+ "using a Sigar proxy cache with a timeout of 30 seconds.",
new MBeanAttributeInfo[] { MBEAN_ATTR_LAST1MIN,
MBEAN_ATTR_LAST5MIN, MBEAN_ATTR_LAST15MIN },
new MBeanConstructorInfo[] { MBEAN_CONSTR_SIGAR }, null, null);
}
/**
* Object name this instance will give itself when being registered to an
* MBeanServer.
*/
private final String objectName;
/**
* <p>Set <code>true</code> when the load average fetch failed with a
* <code>SigarException</code> that indicates the method is not implemented.
* Any subsequent call to this instance will then be answered with
* {@link #NOT_IMPLEMENTED_LOAD_VALUE}.
* </p>
*
* <p><b>FIXME</b> : This is a workaround and should be replaced by something
* more stable, as the code setting this member <code>true</code> relies on
* a substring being present within the exception. A proposal was made at
* <a href="http://jira.hyperic.com/browse/SIGAR-52">issue SIGAR-52</a>.
* </p>
*/
private boolean notImplemented;
/**
* Creates a new instance, using a new Sigar instance to fetch the data.
*
* @throws IllegalArgumentException
* If an unexpected Sigar error occurs.
*/
public SigarLoadAverage() throws IllegalArgumentException {
this(new Sigar());
}
/**
* Creates a new instance, using the Sigar instance specified to fetch the
* data.
*
* @param sigar
* The Sigar instance to use to fetch data from
*
* @throws IllegalArgumentException
* If an unexpected Sigar error occurs
*/
public SigarLoadAverage(Sigar sigar) throws IllegalArgumentException {
super(sigar, CACHED_30SEC);
// all fine
this.objectName = SigarInvokerJMX.DOMAIN_NAME + ":" + MBEAN_ATTR_TYPE
+ "=" + MBEAN_TYPE;
}
/**
* Object name this instance will give itself when being registered to an
* MBeanServer.
*/
public String getObjectName() {
return this.objectName;
}
/**
* @return The load average in the last minute, as a fraction of 1, or
* <code>-1.0d</code> if the load cannot be determined on this platform
*/
public double getLastMinute() {
try {
return sigarImpl.getLoadAverage()[0];
} catch (SigarNotImplementedException e) {
return NOT_IMPLEMENTED_LOAD_VALUE;
} catch (SigarException e) {
throw unexpectedError(MBEAN_TYPE, e);
}
}
/**
* @return The load average over the last five minutes, as a fraction of 1,
* or <code>-1.0d</code> if the load cannot be determined on this
* platform
*/
public double getLastFiveMinutes() {
try {
return sigarImpl.getLoadAverage()[1];
} catch (SigarNotImplementedException e) {
return NOT_IMPLEMENTED_LOAD_VALUE;
} catch (SigarException e) {
throw unexpectedError(MBEAN_TYPE, e);
}
}
/**
* @return The load average over the last 15 minutes, as a fraction of 1, or
* <code>-1.0d</code> if the load cannot be determined on this platform
*/
public double getLast15Minutes() {
try {
return sigarImpl.getLoadAverage()[2];
} catch (SigarNotImplementedException e) {
return NOT_IMPLEMENTED_LOAD_VALUE;
} catch (SigarException e) {
throw unexpectedError(MBEAN_TYPE, e);
}
}
// -------
// Implementation of the DynamicMBean interface
// -------
/*
* (non-Javadoc)
*
* @see DynamicMBean#getAttribute(String)
*/
public Object getAttribute(String attr) throws AttributeNotFoundException {
if (MBEAN_ATTR_LAST1MIN.getName().equals(attr)) {
return new Double(getLastMinute());
} else if (MBEAN_ATTR_LAST5MIN.getName().equals(attr)) {
return new Double(getLastFiveMinutes());
} else if (MBEAN_ATTR_LAST15MIN.getName().equals(attr)) {
return new Double(getLast15Minutes());
} else {
throw new AttributeNotFoundException(attr);
}
}
/*
* (non-Javadoc)
*
* @see DynamicMBean#setAttribute(Attribute)
*/
public void setAttribute(Attribute attr) throws AttributeNotFoundException {
throw new AttributeNotFoundException(attr.getName());
}
/*
* (non-Javadoc)
*
* @see DynamicMBean#invoke(String, Object[], String[])
*/
public Object invoke(String actionName, Object[] params, String[] signature)
throws ReflectionException {
throw new ReflectionException(new NoSuchMethodException(actionName),
actionName);
}
/*
* (non-Javadoc)
*
* @see DynamicMBean#getMBeanInfo()
*/
public MBeanInfo getMBeanInfo() {
return MBEAN_INFO;
}
}

View File

@ -35,7 +35,7 @@ import org.hyperic.sigar.SigarException;
* package. Provides an OpenMBean conform implementation. * package. Provides an OpenMBean conform implementation.
* *
* @author Bjoern Martin * @author Bjoern Martin
* @since 1.4 (2007-04) * @since 1.5
*/ */
public class SigarMem extends AbstractMBean { public class SigarMem extends AbstractMBean {
@ -60,55 +60,34 @@ public class SigarMem extends AbstractMBean {
private static MBeanParameterInfo MBEAN_PARAM_SIGAR; private static MBeanParameterInfo MBEAN_PARAM_SIGAR;
static { static {
MBEAN_ATTR_ACTUAL_FREE = new MBeanAttributeInfo( MBEAN_ATTR_ACTUAL_FREE = new MBeanAttributeInfo("ActualFree", "long",
"ActualFree", "long", "TODO add proper description here", true, false, false);
"TODO add proper description here", MBEAN_ATTR_ACTUAL_USED = new MBeanAttributeInfo("ActualUsed", "long",
true, false, false); "TODO add proper description here", true, false, false);
MBEAN_ATTR_ACTUAL_USED = new MBeanAttributeInfo( MBEAN_ATTR_FREE = new MBeanAttributeInfo("Free", "long",
"ActualUsed", "long", "TODO add proper description here", true, false, false);
"TODO add proper description here", MBEAN_ATTR_RAM = new MBeanAttributeInfo("Ram", "long",
true, false, false); "TODO add proper description here", true, false, false);
MBEAN_ATTR_FREE = new MBeanAttributeInfo( MBEAN_ATTR_TOTAL = new MBeanAttributeInfo("Total", "long",
"Free", "long", "TODO add proper description here", true, false, false);
"TODO add proper description here", MBEAN_ATTR_USED = new MBeanAttributeInfo("Used", "long",
true, false, false); "TODO add proper description here", true, false, false);
MBEAN_ATTR_RAM = new MBeanAttributeInfo( MBEAN_PARAM_SIGAR = new MBeanParameterInfo("sigar", Sigar.class
"Ram", "long", .getName(), "The Sigar instance to use to fetch data from");
"TODO add proper description here", MBEAN_CONSTR_SIGAR = new MBeanConstructorInfo(SigarMem.class.getName(),
true, false, false); "Creates a new instance, using the Sigar instance "
MBEAN_ATTR_TOTAL = new MBeanAttributeInfo( + "specified to fetch the data.",
"Total", "long", new MBeanParameterInfo[] { MBEAN_PARAM_SIGAR });
"TODO add proper description here",
true, false, false);
MBEAN_ATTR_USED = new MBeanAttributeInfo(
"Used", "long",
"TODO add proper description here",
true, false, false);
MBEAN_PARAM_SIGAR = new MBeanParameterInfo(
"sigar", Sigar.class.getName(),
"The Sigar instance to use to fetch data from");
MBEAN_CONSTR_SIGAR = new MBeanConstructorInfo(
SigarMem.class.getName(),
"Creates a new instance, using the Sigar instance " +
"specified to fetch the data.",
new MBeanParameterInfo[]{
MBEAN_PARAM_SIGAR});
MBEAN_INFO = new MBeanInfo( MBEAN_INFO = new MBeanInfo(
SigarMem.class.getName(), SigarMem.class.getName(),
"Sigar Memory MBean, provides raw data for the physical " + "Sigar Memory MBean, provides raw data for the physical "
"memory installed on the system. Uses an internal cache " + + "memory installed on the system. Uses an internal cache "
"that invalidates within 500ms, allowing for bulk request " + + "that invalidates within 500ms, allowing for bulk request "
"being satisfied with a single dataset fetch.", + "being satisfied with a single dataset fetch.",
new MBeanAttributeInfo[]{ new MBeanAttributeInfo[] { MBEAN_ATTR_ACTUAL_FREE,
MBEAN_ATTR_ACTUAL_FREE, MBEAN_ATTR_ACTUAL_USED, MBEAN_ATTR_FREE,
MBEAN_ATTR_ACTUAL_USED, MBEAN_ATTR_RAM, MBEAN_ATTR_TOTAL, MBEAN_ATTR_USED },
MBEAN_ATTR_FREE, new MBeanConstructorInfo[] { MBEAN_CONSTR_SIGAR }, null, null);
MBEAN_ATTR_RAM,
MBEAN_ATTR_TOTAL,
MBEAN_ATTR_USED},
new MBeanConstructorInfo[]{
MBEAN_CONSTR_SIGAR},
null, null);
} }

View File

@ -57,32 +57,40 @@ import org.hyperic.sigar.SigarException;
* it all down again.</p> * it all down again.</p>
* *
* @author Bjoern Martin * @author Bjoern Martin
* @since 1.4 (2007-04) * @since 1.5
*/ */
public class SigarRegistry extends AbstractMBean { public class SigarRegistry extends AbstractMBean {
private static final String MBEAN_TYPE = "SigarRegistry"; private static final String MBEAN_TYPE = "SigarRegistry";
private static final MBeanInfo MBEAN_INFO; private static final MBeanInfo MBEAN_INFO;
private static final MBeanConstructorInfo MBEAN_CONSTR_DEFAULT; private static final MBeanConstructorInfo MBEAN_CONSTR_DEFAULT;
// private static final MBeanOperationInfo MBEAN_OPER_LISTPROCESSES;
static { static {
MBEAN_CONSTR_DEFAULT = new MBeanConstructorInfo( MBEAN_CONSTR_DEFAULT = new MBeanConstructorInfo(
SigarRegistry.class.getName(), SigarRegistry.class.getName(),
"Creates a new instance of this class. Will create the Sigar " + "Creates a new instance of this class. Will create the Sigar "
"instance this class uses when constructing other MBeans", + "instance this class uses when constructing other MBeans",
new MBeanParameterInfo[0]); new MBeanParameterInfo[0]);
// MBEAN_OPER_LISTPROCESSES = new MBeanOperationInfo("listProcesses",
// "Executes a query returning the process IDs of all processes " +
// "found on the system.",
// null /* new MBeanParameterInfo[0] */,
// String.class.getName(), MBeanOperationInfo.INFO);
MBEAN_INFO = new MBeanInfo( MBEAN_INFO = new MBeanInfo(
SigarRegistry.class.getName(), SigarRegistry.class.getName(),
"Sigar MBean registry. Provides a central point for creation " + "Sigar MBean registry. Provides a central point for creation "
"and destruction of Sigar MBeans. Any Sigar MBean created via " + + "and destruction of Sigar MBeans. Any Sigar MBean created via "
"this instance will automatically be cleaned up when this " + + "this instance will automatically be cleaned up when this "
"instance is deregistered from the MBean server.", + "instance is deregistered from the MBean server.",
null /*new MBeanAttributeInfo[0]*/, null /*new MBeanAttributeInfo[0]*/,
new MBeanConstructorInfo[]{ new MBeanConstructorInfo[] { MBEAN_CONSTR_DEFAULT },
MBEAN_CONSTR_DEFAULT}, null /*new MBeanOperationInfo[0] */,
null, null); null /*new MBeanNotificationInfo[0]*/);
} }
private final String objectName; private final String objectName;
@ -95,25 +103,40 @@ public class SigarRegistry extends AbstractMBean {
*/ */
public SigarRegistry() { public SigarRegistry() {
super(new Sigar(), CACHELESS); super(new Sigar(), CACHELESS);
this.objectName = SigarInvokerJMX.DOMAIN_NAME + ":" this.objectName = SigarInvokerJMX.DOMAIN_NAME + ":" + MBEAN_ATTR_TYPE
+ MBEAN_ATTR_TYPE + "=" + MBEAN_TYPE; + "=" + MBEAN_TYPE;
this.managedBeans = new ArrayList(); this.managedBeans = new ArrayList();
} }
/* /* (non-Javadoc)
* @see AbstractMBean#getObjectName() * @see AbstractMBean#getObjectName()
*/ */
public String getObjectName() { public String getObjectName() {
return this.objectName; return this.objectName;
} }
/* (non-Javadoc) /* public String listProcesses() {
* @see javax.management.DynamicMBean#getMBeanInfo() try {
*/ final long start = System.currentTimeMillis();
public MBeanInfo getMBeanInfo() { long[] ids = sigar.getProcList();
return MBEAN_INFO; StringBuffer procNames = new StringBuffer();
for (int i = 0; i < ids.length; i++) {
try {
procNames.append(ids[i] + ":" + sigar.getProcExe(ids[i]).getName()).append('\n');
} catch (SigarException e) {
procNames.append(ids[i] + ":" + e.getMessage()).append('\n');
}
} }
final long end = System.currentTimeMillis();
procNames.append("-- Took " + (end-start) + "ms");
return procNames.toString();
} catch (SigarException e) {
throw unexpectedError("ProcList", e);
}
}
*/
/* (non-Javadoc) /* (non-Javadoc)
* @see javax.management.DynamicMBean#getAttribute(java.lang.String) * @see javax.management.DynamicMBean#getAttribute(java.lang.String)
*/ */
@ -133,11 +156,20 @@ public class SigarRegistry extends AbstractMBean {
*/ */
public Object invoke(String action, Object[] params, String[] signatures) public Object invoke(String action, Object[] params, String[] signatures)
throws MBeanException, ReflectionException { throws MBeanException, ReflectionException {
/* if (MBEAN_OPER_LISTPROCESSES.getName().equals(action))
return listProcesses();
else */
throw new ReflectionException(new NoSuchMethodException(action), action); throw new ReflectionException(new NoSuchMethodException(action), action);
} }
/* (non-Javadoc)
* @see javax.management.DynamicMBean#getMBeanInfo()
*/
public MBeanInfo getMBeanInfo() {
return MBEAN_INFO;
}
// ------- // -------
// Implementation of the MBeanRegistration interface // Implementation of the MBeanRegistration interface
@ -161,6 +193,9 @@ public class SigarRegistry extends AbstractMBean {
// get memory // get memory
registerMemoryBeans(); registerMemoryBeans();
// get system
registerSystemBeans();
} }
/** /**
@ -177,8 +212,10 @@ public class SigarRegistry extends AbstractMBean {
// add CPU bean // add CPU bean
SigarCpu nextCpu = new SigarCpu(sigarImpl, i); SigarCpu nextCpu = new SigarCpu(sigarImpl, i);
try { try {
if (!mbeanServer.isRegistered(new ObjectName(nextCpu.getObjectName()))) if (!mbeanServer.isRegistered(new ObjectName(nextCpu
nextRegistered = mbeanServer.registerMBean(nextCpu, null); .getObjectName())))
nextRegistered = mbeanServer.registerMBean(nextCpu,
null);
} catch (Exception e) { // ignore } catch (Exception e) { // ignore
} }
// add MBean to set of managed beans // add MBean to set of managed beans
@ -189,8 +226,10 @@ public class SigarRegistry extends AbstractMBean {
// add CPU percentage bean // add CPU percentage bean
SigarCpuPerc nextCpuPerc = new SigarCpuPerc(sigarImpl, i); SigarCpuPerc nextCpuPerc = new SigarCpuPerc(sigarImpl, i);
try { try {
if (!mbeanServer.isRegistered(new ObjectName(nextCpuPerc.getObjectName()))) if (!mbeanServer.isRegistered(new ObjectName(nextCpuPerc
nextRegistered = mbeanServer.registerMBean(nextCpuPerc, null); .getObjectName())))
nextRegistered = mbeanServer.registerMBean(nextCpuPerc,
null);
} catch (Exception e) { // ignore } catch (Exception e) { // ignore
} }
// add MBean to set of managed beans // add MBean to set of managed beans
@ -201,8 +240,10 @@ public class SigarRegistry extends AbstractMBean {
// add CPU info bean // add CPU info bean
SigarCpuInfo nextCpuInfo = new SigarCpuInfo(sigarImpl, i); SigarCpuInfo nextCpuInfo = new SigarCpuInfo(sigarImpl, i);
try { try {
if (!mbeanServer.isRegistered(new ObjectName(nextCpuInfo.getObjectName()))) if (!mbeanServer.isRegistered(new ObjectName(nextCpuInfo
nextRegistered = mbeanServer.registerMBean(nextCpuInfo, null); .getObjectName())))
nextRegistered = mbeanServer.registerMBean(nextCpuInfo,
null);
} catch (Exception e) { // ignore } catch (Exception e) { // ignore
} }
// add MBean to set of managed beans // add MBean to set of managed beans
@ -252,6 +293,29 @@ public class SigarRegistry extends AbstractMBean {
nextRegistered = null; nextRegistered = null;
} }
/**
* Registers MBeans for the Sigar types <code>LoadAverage</code>...
*/
private void registerSystemBeans() {
ObjectInstance nextRegistered = null;
// add load average bean
SigarLoadAverage loadAvg = new SigarLoadAverage(sigarImpl);
try {
if (!mbeanServer.isRegistered(new ObjectName(loadAvg
.getObjectName())))
nextRegistered = mbeanServer.registerMBean(loadAvg, null);
} catch (Exception e) { // ignore
}
// add MBean to set of managed beans
if (nextRegistered != null)
managedBeans.add(nextRegistered.getObjectName());
nextRegistered = null;
}
/** /**
* Deregisters all Sigar MBeans that were created and registered using this * Deregisters all Sigar MBeans that were created and registered using this
* instance. After doing so, a super call is made to satisfy {@link AbstractMBean}. * instance. After doing so, a super call is made to satisfy {@link AbstractMBean}.

View File

@ -35,7 +35,7 @@ import org.hyperic.sigar.SigarException;
* package. Provides an OpenMBean conform implementation. * package. Provides an OpenMBean conform implementation.
* *
* @author Bjoern Martin * @author Bjoern Martin
* @since 1.4 (2007-04) * @since 1.5
*/ */
public class SigarSwap extends AbstractMBean { public class SigarSwap extends AbstractMBean {
@ -54,39 +54,30 @@ public class SigarSwap extends AbstractMBean {
private static MBeanParameterInfo MBEAN_PARAM_SIGAR; private static MBeanParameterInfo MBEAN_PARAM_SIGAR;
static { static {
MBEAN_ATTR_FREE = new MBeanAttributeInfo( MBEAN_ATTR_FREE = new MBeanAttributeInfo("Free", "long",
"Free", "long", "The amount of free swap memory, in [bytes]", true, false,
"The amount of free swap memory, in [bytes]", false);
true, false, false); MBEAN_ATTR_TOTAL = new MBeanAttributeInfo("Total", "long",
MBEAN_ATTR_TOTAL = new MBeanAttributeInfo( "The total amount of swap memory, in [bytes]", true, false,
"Total", "long", false);
"The total amount of swap memory, in [bytes]", MBEAN_ATTR_USED = new MBeanAttributeInfo("Used", "long",
true, false, false); "The amount of swap memory in use, in [bytes]", true, false,
MBEAN_ATTR_USED = new MBeanAttributeInfo( false);
"Used", "long", MBEAN_PARAM_SIGAR = new MBeanParameterInfo("sigar", Sigar.class
"The amount of swap memory in use, in [bytes]", .getName(), "The Sigar instance to use to fetch data from");
true, false, false);
MBEAN_PARAM_SIGAR = new MBeanParameterInfo(
"sigar", Sigar.class.getName(),
"The Sigar instance to use to fetch data from");
MBEAN_CONSTR_SIGAR = new MBeanConstructorInfo( MBEAN_CONSTR_SIGAR = new MBeanConstructorInfo(
SigarSwap.class.getName(), SigarSwap.class.getName(),
"Creates a new instance, using the Sigar instance " + "Creates a new instance, using the Sigar instance "
"specified to fetch the data.", + "specified to fetch the data.",
new MBeanParameterInfo[]{ new MBeanParameterInfo[] { MBEAN_PARAM_SIGAR });
MBEAN_PARAM_SIGAR});
MBEAN_INFO = new MBeanInfo( MBEAN_INFO = new MBeanInfo(
SigarSwap.class.getName(), SigarSwap.class.getName(),
"Sigar Swap MBean, provides raw data for the swap memory " + "Sigar Swap MBean, provides raw data for the swap memory "
"configured on the system. Uses an internal cache that " + + "configured on the system. Uses an internal cache that "
"invalidates within 5 seconds.", + "invalidates within 5 seconds.",
new MBeanAttributeInfo[]{ new MBeanAttributeInfo[] { MBEAN_ATTR_FREE, MBEAN_ATTR_TOTAL,
MBEAN_ATTR_FREE,
MBEAN_ATTR_TOTAL,
MBEAN_ATTR_USED }, MBEAN_ATTR_USED },
new MBeanConstructorInfo[]{ new MBeanConstructorInfo[] { MBEAN_CONSTR_SIGAR }, null, null);
MBEAN_CONSTR_SIGAR},
null, null);
} }