Using Aggregations in Macros
Various macros can use aggregations to summarise data, such as counting a list of values, averaging them, and so on. This can be useful in reports so you can see daily, weekly, or monthly values in charts and tables.
Which Macros Use Aggregations?
Some of the more common macros that allow you to use one or more aggregations include:
- [List.GroupBy:]
- [List.SummaryValue:]
- [LogicMonitor.SummaryValue:]
- [LogicMonitor.SummaryValueList:]
How?
In general, specify one or more aggregations using the "aggregations" parameter like this:
aggregations=aggregation type 1;aggregation type 2;...
For example:
[LogicMonitor.SummaryValue: aggregations=Min;Mean;Max;Count;Sum, ...]
What are the Aggregations?
The current list of aggregation is shown below although note that usage my differ slightly between macros. Also note that you should not specify the same aggregation twice in a macro:
Aggregation | Description | Notes / Usage |
---|---|---|
Mean | The mean of the set of values. | |
Min | The minimum of the set of values. | |
Max | The maximum of the set of values. | |
First | The first value in the set. | |
Last | The last value in the set. | |
Count | The count of the values. | |
All | Adds all supported Aggregations. (Not supported in Legacy Mode) | Example: [List.SummaryValue: values=3;2;1, storeAs=a, aggregations=All] { |
PercentConditionMet() | The percentage of the values where a condition was met | Used like this:
The 'value' is a built-in term that is used as a placeholder for the value being used. You can also set the 'outputDateTimes' parameter ONLY for this macro, to obtain a list of the matching DateTimes when the condition succeeded, rather than the percentage value. |
PercentUpTime | The percentage 'uptime' of a LogicMonitor Device (only applies to LogicMonitor.XXX macros in the list).
See the section below for more details of this aggregation. |
|
MinDateTime | The minimum DateTime in the set of data being considered. | Only applies to LogicMonitor.XXX macros in the list). |
MaxDateTime | The maximum DateTime in the set of data being considered. | Only applies to LogicMonitor.XXX macros in the list). |
CountConditionMet() | Similar to PercentConditionMet(), this is simply a count of values where a condition was met. | Used like this:
The 'value' is a built-in term that is used as a placeholder for the value being used. |
Delta | The difference between the first and last double-precision values in the data, i.e. (last double - first double). | |
DeltaPercent | The percentage difference between the first and last double-precision values in the data, i.e. (last double - first double) / first double * 100. | |
Percentile() | The N-th percentile of the data. | Used like this:
The 'value' is a built-in term that is used as a placeholder for the value being used. |
The PercentUpTime Aggregation
The PercentUpTime aggregation is a special case that is designed to use LogicMonitor data to determine the percentage (between two dates) that a particular UNIX-based Device was 'up' for.
Note: When using this aggregation, you MUST set:
- the 'dataSourceInstanceName' parameter to 'SNMP_Host_Uptime'
- the 'dataPoint' parameter to 'Uptime'
This aggregation counts:
- Downtime: "No Data"s immediately preceding a value less than 300 (seconds)
- Uptime: all other values
- Percent Uptime: 100 * UpTimeCount / (UpTimeCount + DownTimeCount)
See the following diagram, where only xi and xi + 1 are considered downtime. All other periods are considered uptime.
Aggregations and Normal or Legacy Mode
You can use two modes in ReportMagic:
- Legacy Mode (the default for Schedules)
- Normal Mode (the default for Report Studio)
In Legacy Mode, variables you might store are treated as text (that is, not strongly typed objects), and the output is often concatenated by special separators (such as a semi-colon), which you can then parse in other macros to extract the values desired.
In Normal Mode (which was designed to make it easier to extract data and avoid issues with complicated text separators), variables are typically stored as objects (for example, a List of strings, or a JArray of integers), and the output will also differ accordingly.
As an example, in Legacy Mode, this macro
([LogicMonitor.SummaryValue: device=My Device, graphName=CPU, dataSourceInstanceName=NetSNMPCPU, dataPoint=UserPercent, aggregations=Min;Mean;Max, storeAs=Summary])
might output something like:
1.51;75.00;136.81
Whereas in Normal Mode, the output might be like this:
{ "DeviceId": 123, "DeviceDisplayName": "My Device", "DataSourceName": "NetSNMPCPU", "DeviceDataSourceInstanceName": "NetSNMPCPU", "DeviceDataSourceInstanceId": 123, "DataPointName": "UserPercent", "Aggregations": { "Min": 1.51, "Mean": 75.00, "Max": 136.81 } }
The entire result is output / stored as an 'object' (a JObject). You can then use further macros to extract the aggregations you want and store them into variables, for example:
[Object.Unpack: value=`{Summary}`, properties=Aggregations.Min;Aggregations.Mean;Aggregations.Max, storeAs=Min;Mean;Max]
The Object.Unpack macro takes in the previously-stored variable (Summary) and then based on the properties parameter, extracts the three aggregation values which it stores in the variables Min, Mean and Max.
Using Multiple Aggregations
Normal Mode
You can use multiple different aggregations in a macro like in the following:
[List.SummaryValue: values=10;9;8;7;6;5;4;3;2;1, aggregations=Percentile(25);PercentConditionMet(value>25);CountConditionMet(value>75);Count;Mean;Min;Max;First;Last;Sum]
But if you want to find out, for example multiple different sets of PercentConditionMet() aggregations, you can now specify it like:
[LogicMonitor.SummaryValueList: matchAppliesToQuery=`isWindows() && displayName != "dev.panoramicdata.com"`, dataPointSpecs=WinCPU^-1^CPUBusyPercent, aggregations=PercentConditionMet(value>5) as Percent5;PercentConditionMet(value>10) as Percent10;PercentConditionMet(value>20) as Percent20]
It is set out in the following way: Aggregation as newname.
This applies to all of the aggregations in the above table and you can specify more than one Aggregation as per macro:
[LogicMonitor.SummaryValue: device=pdl-dr-prod-01, graphName=CPU, dataSourceInstanceName=NetSNMPCPU, dataPoint=UserPercent, aggregations= Percentile(25) as Percentile1;Percentile(75) as Percentile2;PercentConditionMet(value>25) as PercentConditionMet1;PercentConditionMet(value>75) as PercentConditionMet2;CountConditionMet(value>25) as CountConditionMet1;CountConditionMet(value>75) as CountConditionMet2;Count as Count1;Count as Count2;Mean as Mean1;Min as Minimum;Max as Maximum;First as First1;Last as Last1;Sum as Sum1]
Legacy Mode
In Legacy mode, multiple aggregations (even of the same type) do not cause an issue, and just output in the normal way e.g. a semi-colon or caret-delimited list such as:
100.00^200.00^...etc