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.

Collection Type Groovy Variables
SNMP output: the snmp payload is represented as array, with each oid/response pair represented as an element separated by '='
HTTP status: the status code of the http client (1 - 5), with 5 being connection failed
responseTime: response time in milliseconds
output: entire http response including header and body
body: http body only
WMI output: a map containing each of all the properties of the specified WMI class with the property names (in upper case) as keys
JMX output: a map containing each of the specified mbeans and their raw values


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:

// iterate through output array
{ line ->
    (oid, value) = line.toString().split('=');

    // get inOctet and outOctet values
    if (oid.startsWith("."))
        totalInOctets = value.toFloat();
    else if (oid.startsWith("."))
        totalOutOctets = value.toFloat();

// sum the values and return
totalOctets = totalInOctets + totalOutOctets;

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 
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:

rawDate = output["solr/##WILDVALUE2##:type=/replication,id=org.apache.solr.handler.ReplicationHandler:replicationFailedAt"];
Date fd = Date.parse( 'EEE MMM dd HH:mm:ss z yyyy', rawDate );
today = new Date();
timeDiff = (today.time - fd.time)/1000;
return (timeDiff);

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

if (status < 2)
    myStatus = 5;
    myStatus = 10;


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.