Groovy Complex Datapoints
In most cases, you can use the Standard Complex Datapoint mechanism to manipulate collected data. But when you need to do additional processing not possible with datapoint expressions you can turn to Groovy scripting for more full-featured datapoint calculations.
When you use Groovy to construct a complex datapoint, the Collector pre-populates Groovy variables with the raw data collected from normal datapoints. The type and syntax of these objects varies based on the collection mechanism employed. See the table below for the variable name(s) assigned based on the collection type.
Note that Groovy Complex Datapoints reference the raw data exactly as it's collected, e.g. as a "gauge" datapoint, rather than calculated as a rate such as "counter" or "derive" datapoint.
Once you've processed your data in Groovy, you'll need to use the return(); method to pass the calculated value back to the Collector for storage.
Example — Groovy Complex Datapoint using WMI
Consider a WMI datasource that queries the class Win32_OperatingSystem. If you needed to use the raw date output from the WMI class you would write something like:
Example — Groovy Complex Datapoint using SNMP
Next consider a SNMP datasource that queries interface data, such as snmp64_If-. If you wanted to some calculations on the raw values returned you might do something like this:
Example — Groovy Complex Datapoint using JMX
In this example, consider a JMX Mbean that returns a time as a date string. There are many ways of presenting time as a string, so LogicMonitor cannot include a post-processor for all possible formats - but this is easily achieved with a Groovy script. If the Mbean solr/##WILDVALUE2##:type=/replication,id=org.apache.solr.handler.ReplicationHandler:replicationFailedAt returns a time in the form "Thu Sep 11 06:40:30 UTC 2016", and we wish to create a datapoint that reports the time since now and the time of that Mbean, we could use the following as the Groovy code:
Example — Groovy Complex Datapoint using HTTP
Here's a simple example of how you might use Groovy to manipulate the status code returned by the HTTP collection mechanism
Device & Instance Properties in Complex Datapoints
Note that you can use Device or Instance Properties you've collected within a Groovy Complex Datapoint calculation. Instance Properties apply in only to WMI & SNMP collection mechanisms, and requires Collector version 22.084 and higher.
Device or instance properties can be referenced within Groovy as either:
to retrieve a device property,
to retrieve an instance property, or
to retrieve a property of either type.
See our documentation on Embedded Groovy Scripting for more details and examples.