Sun Microsystems
Products & Services
 
Support & Training
 
 

Previous Previous     Contents     Index     Next Next

Finally, an instance of Agent, agent, is started on the appropriate SNMP port by calling the start method defined in Example 18-13.

18.2.4 Running the SNMP Table Instrumentation Example

After you have run mibgen to generate JMX_MBEAN_SERVER_MIB and its associated classes, as explained in 18.2.1 Classes Generated by mibgen, you can run the example.

ProcedureTo Run the SNMP Table Instrumentation Example

Run the example from the examplesDir/current/Snmp/MBeanTable directory.

  1. Compile the Java classes in the generated directory.

    $ cd generated
    $ javac -d .. *.java

    This creates the compiled *.class files into the examplesDir/current/Snmp/MBeanTable directory, rather than in generated, so that they are accessible to the other classes used in the example.

  2. Compile the Java classes in the examplesDir/current/Snmp/MBeanTable directory.

    $ cd ..
    $ javac -d . *.java

  3. Start the Agent.

    You have several options when starting the Agent class.

    • To start the Agent on the default SNMP port, 16161:

      $ java  Agent service:jmx:jmxmp://

    • To start the Agent on a port of your choice:

      $ java  -Dsnmp.port=port_number Agent service:jmx:jmxmp://

    • To start the Agent with a connector of your choosing, you can specify a different service URL and connector port. For example:

      $ java  Agent JMX_service_URL

    In any of the above cases, you see confirmation of the SNMP port used, confirmation of the creation of the connector and then the alternating registration and deregistration of sets of five MBeans.

  4. You can now perform management operations on the Agent.

    Use a JMX management console of your choice to examine the content of the MBean server through a JMXMP connector.

    Use the SNMP management application, easymanager, that is supplied with Java DMK to examine the JMX-MBEAN-SERVER-MIB through SNMP. You can find the easymanager application in the installDir/contributions/easymanager directory.

ProcedureTo Examine JMX-MBEAN-SERVER-MIB Using easymanager

  1. Add the JMX-MBEAN-SERVER-MIBOidTable.class to your classpath.

    Type the following command if you are using a UNIX platform:

    $ export CLASSPATH=$CLASSPATH:examplesDir/current/Snmp/MBeanTable/

    Type the following command if you are using a Windows platform:

    set classpath=%classpath%;examplesDir/current/Snmp/MBeanTable/

  2. Open installDir/contributions/easymanager/bin

  3. Start easymanager.

    If the SNMP agent has been started with the default example port, type the following command.

    $ easymanager.sh -port 16161 

    You can now use easymanager to perform the following operations.

    • Pop up a MIB discovery window.

      discovermib -p JDMK_STD_V2_profile

    • Create a new MBean.

      set:2 -w private :<<jmxMBeanObjectName.998,4,Test:name=test1>,
      <jmxMBeanClassName.998,4,Agent$Simple>,
      <jmxMBeanRowStatus.998,2,4>>

    • Click on resynch in the MIB discovery window to observer the changes in the MIB.

    • Destroy the MBean you created.

      set:2 -w private :<<jmxMBeanRowStatus.998,2,6>>

18.3 Virtual SNMP Tables

This example shows how to implement virtual SNMP tables when instrumenting a MIB in Java DMK. It is based on the same MIB as the one used in the MBean Table Instrumentation example, so you should make sure you have run that example before running this one. However, the fundamental difference between this example and the SNMP Table Instrumentation example is that the tables implemented remain entirely virtual. The tables are calculated whenever they are needed by an SNMP request, rather than residing permanently in the SNMP session. The virtual table is also created with a limited period of validity. Once this period has expired, if the request for which the table was calculated has been executed, the table can be garbage-collected. There are thus two main advantages to operating with virtual tables rather than with tables that are permanently present.

  • Coherency: A table snapshot is calculated when a request is received, unless there is already a valid table snapshot present. Every snapshot is an immutable object. Consequently, the table snapshot will remain coherent with the context of the request for the entire duration of the execution of that request.

  • Resource usage: Unused and expired tables can be garbage-collected. Consequently, as long as there are no requests arriving, there is no redundant table consuming resources unnecessarily, and no need to continue updating the table when no managers are making requests.

The virtual SNMP table example is based on the classes in the examplesDir/current/Snmp/MBeanVirtualTable directory. It defines the MIB called JMX-MBEAN-SERVER-MIB that exposes the content of an MBean server through SNMP. This MIB is the same as the one defined in the previous example. To achieve this, JMX-MBEAN-SERVER-MIB defines the same two SNMP tables as before:

  • jmxMBeanTable, which has read-create access permission, and contains one row per MBean registered in the remote MBean server.

  • jmxMBeanAttrTable, which has read-only access permission, and extends the jmxMBeanTable. For each MBean mirrored in the jmxMBeanTable, it contains one additional row per attribute exposed by this MBean.

18.3.1 Classes Generated by mibgen

Before you can proceed with this example, you need to generate the JMX-MBEAN-SERVER-MIB and it's associated classes, by using the mibgen compiler supplied with Java DMK. For details of the mibgen compiler, see the Java Dynamic Management Kit 5.1 Tools Reference Guide.

ProcedureTo Generate the JMX-MBEAN-SERVER-MIB

The example MIB is contained in the configuration file JMX-MBEAN-SERVER-MIB.mib, which is found in examplesDir/current/Snmp/MBeanVirtualTable. You should run the example from within this directory.

  1. Ensure that your PATH environment variable knows where to find mibgen.

    In a default installation, mibgen is found in installDir/bin.

  2. Create a new directory, generated, inside examplesDir/current/Snmp/MBeanVirtualTable.

    $ mkdir generated

    This directory is where mibgen generates the classes associated with JMX-MBEAN-SERVER-MIB.mib.

  3. Run the mibgen compiler.

    $ mibgen -X:use-display-hint -X:no-table-access -X:abstract-mib \
               -d generated JMX-MBEAN-SERVER-MIB.mib

    The advanced mibgen option use-display-hint instructs mibgen to generate an attribute of type String for any object using a textual convention whose DISPLAY-HINT is 255a. This option is used because JMX-MBEAN-SERVER-MIB defines textual conventions (for example, JmxMBeanObjectNameTC) which must be translated into java.lang.String attributes, rather than the default Byte[] attributes.

    The -X:no-table-access option instructs mibgen not to generate a table accessor in the group MBean interfaces. The effect of this is that the accessors used to return the TableJmxMBeanTable and TableJmxMBeanAttrTable table objects are not created.

    The -X:abstract-mib option, as the name suggests, generates an abstract MIB. In this case, the MIB class is an abstract class, in which the MBean factory methods are also abstract.

    The -d generated option sends the output of mibgen to the newly created generated directory

    Using the first two options makes it possible to get rid of any references to the default JmxMBeanServer class, as well as to its associated Table* objects. These classes are still generated, but our customer implementation no longer references them.

The MIB used in this example is the same as the one used in the SNMP table instrumentation example. Consequently, mibgen generates the same files in the generated directory as were generated in the table instrumentation example. The differences between this example and the instrumentation example are found in the customized classes, that are used to extend the generated classes.

Previous Previous     Contents     Index     Next Next