BatchScript Data Collection
Last updated on 18 June, 2025The BatchScript collection method in LogicMonitor enables efficient monitoring of multiple instances within a single device—such as disks, interfaces, or services—using one script execution per polling cycle. This method is ideal for devices with many instances or those that do not support instance-specific SNMP queries or APIs.
During each polling cycle, the LogicMonitor Collector executes the configured script once per device. The script, which can either be embedded directly in the DataSource or uploaded as a separate file, collects and outputs metrics for all discovered instances in a single execution. LogicMonitor captures this output through standard output (stdout) and applies the selected post-processing method—such as multi-line key-value pairs or JSON—to extract datapoint values. While this process mirrors that of the standard Script collection method, BatchScript is significantly more scalable for monitoring devices with a large number of instances.
BatchScript supports multi-instance data collection by dynamically mapping collected metrics to instance names using the ##WILDVALUE##
token. This token is used in datapoint key definitions, not within the script body.
If a script returns output in the following format:
disk1.iops=9024
disk1.throughput=563
disk2.iops=4325
disk2.throughput=452
Datapoints should use the multi-line key-value pairs post-processing method with keys formatted as the following:
##WILDVALUE##.iops
##WILDVALUE##.throughput
During processing, LogicMonitor replaces ##WILDVALUE##
with the actual instance name (for example, disk1
, disk2
), associating each value with the correct instance.
Because BatchScript executes once per device, consider the following with the script:
- You cannot use
instanceProps.get()
to retrieve instance-specific properties. - Tokens like
##WILDVALUE##
and##WILDALIAS##
are not usable inside the script. - You can access all wildvalues in a loop using
datasourceinstanceProps
.
def listOfWildValues = datasourceinstanceProps.values().collect { it.wildvalue }
datasourceinstanceProps.each { instance, instanceProperties ->
instanceProperties.each
{ it -> def wildValue = it.wildvalue // Do something with wild value }
}
This approach allows your script to dynamically generate metrics for all discovered instances in a single execution.
Requirements for Configuring a Datapoint using the BatchScript Collection Method
Your script must return one of the following:
- Multi-line key-value pairs—where each line represents an instance and its metric.
For example:instance1.key1=value11
instance2.key1=value21
instance1.key2=value12
instance2.key2=value22
Use the Multi-line key-value pairs post-processing method.Datapoint keys must follow the following format:##WILDVALUE##.key1
##WILDVALUE##.key2 - JSON—using a structured object format compatible with the post-processing method
For example:{
"data": {
"instance1": {
"values": {
"key1": value11,
"key2": value12
}
},
"instance2": {
"values": {
"key1": value21,
"key2": value22
}
}
}
}
Use the JSON/BSON object post-processing method.Datapoint keys must follow the following format:
data.##WILDVALUE##.values.key1
data.##WILDVALUE##.values.key2
When defining datapoints, you must use the ##WILDVALUE##
token in the key field to map values to individual instances. This token is resolved dynamically by LogicMonitor during processing and is required for proper multi-instance mapping. If ##WILDVALUE##
contains unsupported characters (for example, :, #, \, or spaces), NoData will be returned.
Recommendation: Replace invalid characters in instance names with underscores (_) or dashes (-) in both Active Discovery scripts and script output.
Considerations for using the BatchScript Collection Method
BatchScript as a collection method is intended for multi-instance DataSources. When configuring your DataSource, ensure that has multi-instance enabled, along with Active Discovery.
Note: The collector.batchscript.timeout
setting in agent.conf
applies only to batchScripts. It does not apply to PowerShell scripts, which run in a separate process with a fixed, non-configurable timeout.
If your PowerShell script outputs large volumes of data, use Write-Output
instead of Write-Host. Write-Output is more efficient for sending data to stdout
and can help reduce the risk of timeout issues.
Configuring a Normal Datapoint using the BatchScript Collection Method
- In LogicMonitor, navigate to Modules and either add a new DataSource or select the module you want to add a datapoint to for collecting BatchScript data.
For more information, see Custom Module Creation or Modules Management. - Configure or modify the module as needed, and ensure “BatchScript” is selected from Collection Method.
- Ensure Multi-Instance and Active Discovery are enabled.
- Complete Active Discovery form. For more information, see Active Discovery.
- To configure the normal datapoint to collect BatchScript data, select Add a Normal Datapoint.
- In the Name field, enter a name for the datapoint.
- In the Description field, enter a description
- In the Datapoint source field, select Content the script writes to the standard output.
- In the Interpret output with field, select Multi-line key-value pairs.
- In the Key field, enter “
##WILDVALUE##.Datapoint Name
“
For example, if the datapoint name is read_bytes_per_second, the key is##WILDVALUE##.read_bytes_per_second
. - Configure or modify the additional settings for the datapoint as needed.
- Select save.