Monday February 20, 2006 ![]() |
JMX, SNMP, Java, etc...Daniel Fuchs blogs on JMX, SNMP, Java, etc... |
... or the Hitchhiker's Guide to SNMP, Part-II. Before I can launch into a blog about understanding the JVM-MANAGEMENT-MIB, I will need to say a few words about SNMP MIBs in general, and more particularly, about how SNMP data is structured. These will be the miscellaneous stops we will make in our hitchhiking journey: IntroductionIn previous entries, I have briefly talked about SNMP itself, and introduced the Tiger (and Mustang)
JVM SNMP agent. For those advanced readers who wish to acquire more background, RFC 3584 - Coexistence between Version 1, Version 2, and Version 3 of the Internet-standard Network Management Framework, explains all the fine points of why and how SMIv2 MIBs can be implemented by agents supporting any of the existing SNMP protocol versions - therefore obsoleting SMIv1. At this point, it is not in my intention to launch in a full-fledged tutorial about MIBs and SNMP - and were I to do so, I wouldn't probably have the requisite editorial skills. My ambitions are more humbly to get you started on understanding how SNMP (the protocol) and MIBs (the data accessed by the protocol) work, so that you may practice with our little JVM agent. The Global OID TreeAt the root of the structure of SNMP data - is the concept of OBJECT IDENTIFIER,
or OID. In my previous blog I have briefly explained the concept of OBJECT-IDENTIFIER.
In particular, I have explained that all SNMP definitions - MIBs, objects,
etc... are identified by their OID in the global OID tree. I have also
shown how enterprises can obtain a sub-node in the
There, a whole sub-tree has been reserved for the JVM-MANAGEMENT-MIB, whose root is defined at:
From now on, I will therefore use the label
SNMP and OBJECT IDENTIFIERSAn important thing to note is that OIDs are not only used to register global definitions, but also to identify the corresponding pieces of data that can be retrieved from an SNMP Agent implementing these definitions. Let me take an example. In the JVM-MANAGEMENT-MIB, we have defined a scalar variable that represents the current count of living threads. This variable is defined by the following OBJECT-TYPE definition, extracted from the JVM-MANAGEMENT-MIB:
This means that to get the
It is also important to note that only terminal values (leaves of the tree) can
be accessed through the SNMP protocol. This is why scalar variables are accessed with a trailing SNMP is SimpleNow one of the reasons why we say that SNMP is simple, is because SNMP and SMIv2 will only allow you to define, expose, get, and set values of simple types. The types supported by the SNMP protocol and SMIv2 are defined in STD 58, RFC 2578. I will not go and describe all these types, and the interested reader is invited to go directly at the source in RFC 2578. To sketch it, we can say that SNMP allows you only to expose:
Scalar Objects and Columnar ObjectsIn SMI, we will find two kinds of objects that you can GET and SET: scalar objects, of which jvmThreadCount is an instance, and columnar
objects, which allow us to represent tables. Tables are probably the
most complex things that you will encounter in SNMP. This is because a) all the
data in SNMP is registered in a tree structure, which does not map quite naturally
to two-dimensional [column/row] tables, and b) the protocol itself has no verb for CREATE/INSERT/DELETE, so all creation/deletion of rows in tables has to be
performed by means of SET requests. Defining Tables in SNMPIn SMIv2, tables are defined in this way:
This defines a table called jvmRTInputArgsTable whose rows are modeled as instances of JvmRTInputArgsEntry. Conceptual RowsIn fact, in SNMP, we do not speak of rows, but rather of conceptual rows. This is because there doesn't exists such a thing as a row in an OID tree: there doesn't exist such a thing as an instance of JvmRTInputArgsEntry, that you could identify by a single OID, and that you could get and set. What we have in the OID tree, and what you can get and set with SNMP, are individual table cells, identified by the OID of the column you're looking at, and the index of the conceptual row that intersects with that column. So here is how you define a conceptual row:
The first construct (jvmRTInputArgsEntry is an OBJECT-TYPE that
identifies the definition of the conceptual row itself. You will notice that
this OBJECT-TYPE, like the OBJECT-TYPE that declares the table itself, is said
to be not-accessible. This is because, as I have stated earlier, these objects are not value leaves of the OID tree, and therefore cannot be returned.
The second construct is not an OBJECT-TYPE, but is the ASN.1 definition of
the pseudo-type of the conceptual row. This pseudo-type is declared to be a
JvmRTInputArgsEntry, are not things that can be returned by SNMP agents. The only things that will be returned by the SNMP agent - and only if it is asked politely, are the instances of jvmRTInputArgsItem. Let's see how this works... Definition of Index and Non-Index Columnar ObjectsTo complete the definition of our small input argument table, we must now define its two columns:
defines the jvmRTInputArgsIndex index column. There are two things that are noticeable about this definition. First, this index object is declared to be not-accessible. Why? because of The Chicken, and because of The Egg. Namely, to GET the value of the index, you would have to know the value of the index in the first place: asking for "hey, I want the value of the index where the value of the index is Z" would simply get you Z. This would be completely irrelevant and SMIv2 thus mandates that all indexes be declared as not-accessible - there is one exception, which I'm not going to detail - when the table contains only indexes - e.g. when it simply defines relationships between indexes in other tables. However, this is for 2nd year in SNMP, so let's forget about this for now - readers etc... STD 58, RFC 2578 etc... ;-) TEXTUAL-CONVENTIONSThe second thing that is noticeable about this definition is the value of
the SYNTAX clause, which is defined to be
The End Is Close!Finally, and to complete our table, we still need to define the only piece of data that we will be able to access, the real content of the table, its unique non index column (unique in this case: tables can have multiple indexes and multiple non index columns), the jvmRTInputArgsItem:
This, dear reader who has been patient enough to follow me this far, is the
actual data that is contained in this table - which makes it possible to
retrieve, using the SNMP protocol, each of the Getting an Instance of a Columnar ObjectSo to get the value of args[i], and according to all these definitions
we've been examining so far, you will simply need to send a GET request for the
following OID:
The End! Don't miss the next episode in our SNMP series!In some next entries, I'll do a follow-up to explain how you can discover the content of a table by sending GET-NEXT request, how you can compose the index part of an OBJECT-IDENTIFIER when the index value is a string, and how to work with tables which have multiple indexes. But I think you will agree with me, this would be definitely too much for tonight... Sleep Well! Grenoble, France, one night at 12pm... Tags: snmp Posted by dfuchs ( Feb 20 2006, 10:58:54 AM CET ) Permalink Comments [18] |
Posted by C. Sridhar on June 08, 2006 at 10:14 AM CEST #
Thanks for reading!
-- daniel
Posted by daniel on June 08, 2006 at 02:21 PM CEST #
Hi Daniel:
Excellent blogs! Your info on SNMP is concise and to the point. When can I expect the entry you promised about GET-NEXT? ("In some next entries, I'll do a follow-up to explain how you can discover the content of a table by sending GET-NEXT request")
Kind regards,
Frank Kieviet
Posted by Frank Kieviet on November 30, 2006 at 05:18 AM CET #
Your interest is noted. But I have an entry about multi-indexed tables in preparation first.
Cheers and thanks for reading,
-- daniel
Posted by daniel on December 10, 2006 at 09:20 PM CET #
Posted by Reza Amiri on January 12, 2007 at 08:33 AM CET #
I'm glad you found my blog useful!
Thanks a lot for letting me know with such enthousiasm :-)
-- daniel
Posted by daniel on January 12, 2007 at 12:11 PM CET #
Hi, great blog, I'm a snmp beginner , and the article helped me to understand a little bit of Columnar Object.
I do have one question:
If you have conceptual table with several rows, will you have to define a different entries for each row?
Thanks again.
Posted by Edo on August 12, 2008 at 10:27 AM CEST #
can some one plz post a simple snmp program.. a get requset to some OID..
Posted by 122.169.200.2 on November 12, 2008 at 11:47 AM CET #
in which folder should the jvm-management.mib should be kept??
Posted by ravi on November 12, 2008 at 11:49 AM CET #
Hi Ravi,
The jvm-management.mib is a specification - if you will, it's like javadoc.
If you want to write a Java program that gets an SNMP OID you can use for instance OpenDMK
http://opendmk.dev.java.net/
If you want to do it from a shell script you can use for instance NET-SNMP (on UNIX try: man snmpget).
hope this helps,
-- daniel
Posted by daniel on November 12, 2008 at 12:22 PM CET #
hey daniel,
thanks a lot for the reply,and one more question..
i tried to retrieve the value of the snmp variable corresponding to the oid=" 1.3.6.1.4.1.42.2.145.3.163.1.1.2.11" (jvmmemoryheapusage) by a simple snmp get request..but not getting any result.
Is it because i have not installed any java dynamic management kit?is dmk a must for any snmp operations with the java virtual machine?
Posted by ravi on November 13, 2008 at 07:03 AM CET #
Hi,
1) You need to start the Java app you want to monitor with the appropriate flag - in order to start the SNMP daemon:
http://java.sun.com/javase/6/docs/technotes/guides/management/snmp.html
2) If you are using snmpget to get the OID make sure that you are using the correct community string configured for the agent (see http://java.sun.com/javase/6/docs/technotes/guides/management/snmp.html)
3) When you get a scalar object you need to append .0 to the OID, so what you need to get is in fact jvmMemoryHeapUsed.0, which is 1.3.6.1.4.1.42.2.145.3.163.1.1.2.11.0, as explained here:
http://blogs.sun.com/jmxetc/entry/understanding_the_structure_of_management#OIDs
-- daniel
Posted by daniel on November 13, 2008 at 12:45 PM CET #
thanx a lot daniel , it worked.. thank you
Posted by ravi on November 14, 2008 at 11:28 AM CET #
hi daniel,
the above explanation worked,
i could find values for the oids of "jvmthreadcount","jvmdeamonthreadcount" n some others which returned Gauge32 or a Counter32 but when i looked for the value of any snmpvariable that returned Counter64,i dint get any response..
i did both of them with snmp.get() method..
what can be the problem?
thank you
Posted by ravi on November 14, 2008 at 01:23 PM CET #
Hi ravi,
To get 64 bits values you need to use the version 2 (SNMPv2c) of the SNMP protocol. 64 bits are not supported by SNMP v1. For instance if you're using snmpget you need to call it with the flag -v 2c
-- daniel
Posted by daniel on November 14, 2008 at 01:41 PM CET #
hi daniel,
your suggestions were really helpful,I learnt most of what i know about snmp from your blogs.. keep blogging
thanks a lot
Posted by ravi on November 17, 2008 at 06:36 AM CET #
Hi Daniel,
your suggestions were really helpful and I want to know whether snmpgetnext() method will work fine even for scalar objects?
snmpget() method is not working fine for tabular objects..y?..could u plzzz explain me these things in details...am very confused...
Thanks in Advance...
Malar
Posted by Malar on November 25, 2008 at 09:11 AM CET #
Hi Daniel
Thanks very much for this exceptionally clear explanation. I'm putting together some background for one of our J2EE teams who are just getting into SNMP - is it allowable for me to copy and paste some of this content (with complete attribution to you, of course) to use in an internal guide?
Regards
Scott
Posted by Scott on July 01, 2009 at 11:33 PM CEST #