From OpenNMS
Here's a very rough outline of how to add a new type of collector to collectd. You would do this if you want to get collect and store data from some currently unsupported protocol which is roughly equivalent to the existing SNMP, JMX, NSClient or HTTP Collectors.
Create a class which implements ServiceCollector
- The
initialize(Map parameters)method will be called at startup. - The
initialize(CollectionAgent agent, Map parameters)method will be called for each node (CollectionAgent) that has been scheduled (this is where you setup any permanent objects which contain state, configuration or connection objects for that particular node/agent). - The respective release methods will be caused at shutdown or if a node should no longer be collected.
- Most importantly, when a node should be collected, the
collect(CollectionAgent agent, EventProxy eproxy, Map<String, String> parameters)method is called. This is the guts of the data collection, and should return a object which implements CollectionSet.
A CollectionSet is the results of collection. This object contains a set of CollectionResources, which contain sets of AttributeGroups which contain sets of CollectionAttributes.
- Examples of a CollectionResource would be
- the node level data for a node,
- the interface level data for a single interface, or
- an indexed table in SNMP
- I'm not entirely sure at this writing, but I believe AttributeGroups are used to group attributes into single RRDs/JRBs, when StoreByGroup is active. I further believe that they correspond to the groups in the datacollection.xml. They are not (I think) used for other than SNMP, but feel free to do so. NSClient should probably use them too, but doesn't currently
- CollectionAttribute's are the actual data points
You will need to create classes that implement CollectionResource and CollectionAttribute to populate your CollectionSet (see the classes AbstractCollectionResource and AbstractCollectionAttribute for handy partial implementations). You'll probably also need to create a class which implements CollectionAttributeType.
In practice, for any simple protocol, I recommend you copy and modify either NSClientCollector or HttpCollector. They are both self-contained collectors-in-a-file, utilising inner-classes for the various support classes that implement all those interfaces.
Start by modifying the collect method to do whatever you need to do, then see what falls out from there. Other changes that will probably be needed
- Modifications to the
initializemethods based on what you need in the way of state across collections, - renaming all the classes
- tweaking how you get your values from your protocol of choice into the CollectionSet structure
- configuration files (see below)
Things you'll also have to do
These are beyond the scope of this particular page, but are necessary none-the-less
- Implement your own config files and configuration manager/factory classes, in whatever fashion is necessary to support specifying the data to be collected. I recommend you follow the general style of the existing xml files, and config classes.
- Add some config to collectd-configuration.xml to cause collectd to create and schedule your ServiceCollector subclass. You're looking to add a
<service name="XYZ" interval="300000" user-defined="false" status="on">section and a<collector service="XYZ" class-name="org.opennms.netmgt.collectd.XYZCollector"/>near the end; check the existing configuration for examples
Things you get for free
- Storing in the RRD or JRobin files on disk. This is done for you by collectd, by visiting your CollectionSet
- Thresholding. Again, collectd does this for you, in association with some classes in the threshd package.
More importantly, *do* *not* re-implement these yourselves; it's bad karma, and I shall hunt you down if you do.






