SNMP Monitoring of Solr Statistics (through JBoss)
There are likely several ways of doing this, including finding some libraries (open source or otherwise) that expose MBean attributes through SNMP. However, one of the easiest methods is to use the snmp-adapter.sar that comes with JBoss 4.0.5.GA and above. This page shows how to add an SNMP-adapter that exposes one attribute, the "standard" QueryHandler's request count.
The snmp-adapter.sar can be found in the server/all/deploy directory. You'll want to copy it into your server instance's deploy directory.
Private Enterprise Number (OID)
In order to use SNMP monitoring, you will need to have your own Private Enterprise Number (OID). You can apply for one at IANA's website, and if it's approved it will show up in the IANA's master list.
Configuring the exposed attributes
Using your OID (let's say it's 12345678 for XYZ Corp.), you'll want to edit the attributes.xml included in the snmp-adapter.sar to add something like the following:
Creating the MBean
You'll want to create an MBean interface that looks something like this:
And for the implementation, I have chosen to make most of the accessor methods static because in my implementation other pieces of code access the stats as well. The implementation looks like this:
Note that I've stripped out the imports and a bunch of exception-handling code in order to keep this code section as brief as possible, and names have been changed to protect the innocent. You'll want to handle potential null returns, etc.
Initializing and Registering the MBean
Solr uses a filter to direct its traffic (SolrDispatchFilter), and inside that filter is a member variable that contains the Solr cores (of type org.apache.solr.core.CoreContainer). Because that member variable is not exposed in any way, you'll have to extend the filter in order to get to the CoreContainer. You should end up with code that looks like this:
Again, you may not want to do your error-handling that way, but you get the picture. You'll note where we use the JNDI name the same way we specified it in attributes.xml.
In order to make sure the filter is used, you must deploy your classes (MBean classes and filter) along with Solr. For now we'll assume you've done that by placing them inside the solr.war.
You must also edit the web.xml in the solr.war file to change the SolrRequestFilter to use your extended filter:
Testing the exposed SNMP attributes
Once that's done, simply deploy your new war file into JBoss and start it up. A good way to test SNMP locally is by using NET-SNMP. With that installed, you can run commands like this:
Note the use of the Private Enterprise Number in the OID! A command like that (or a specific value using "snmpget") should yield results like this if everything's working:
One problem I've noticed with the SNMP adapter SAR is that although it seems to be able to figure out how to expose "String" and "long" types properly, it does not expose "double" types properly (and it gives no errors about them either, which is troublesome). That means that attributes such as the standard query-handler's avgTimePerRequest statistic should probably be exposed as Strings. Of course, if you can get the double values working, please feel free to edit this wiki and enlighten us all.
Another thing I've noticed is that when an SNMP attribute cannot be exposed, the NET-SNMP snmpwalk will quit walking upon the first variable that gives it cannot retrieve, however the following attributes may still be exposed properly.