Skip to main content
Version: 1.3.0

Divide

Arithmetic Data Analysis

Synopsis

Performs division operations on numeric values.

Schema

- divide:
field: <ident>
left_operand: <string>
right_operand: <string>
description: <text>
if: <script>
ignore_failure: <boolean>
ignore_missing: <boolean>
on_failure: <processor[]>
on_success: <processor[]>
tag: <string>

Configuration

The following fields are used to define the processor:

FieldRequiredDefaultDescription
fieldY-Target field to store the division result
left_operandY-Dividend (numerator) - can be a literal value or field reference
right_operandY-Divisor (denominator) - can be a literal value or field reference
descriptionN-Explanatory note
ifN-Condition to run
ignore_failureNfalseContinue processing if division fails
ignore_missingNfalseSkip if referenced fields don't exist
on_failureN-Error handling processors
on_successN-Success handling processors
tagN-Identifier

Details

Performs a division operation between two numeric values and stores the result in a target field. The processor can use literal values or extract values from existing fields in the log entry.

note

Numeric values are automatically converted to appropriate types for calculation. The processor accepts both literal values and field references for operands.

The processor automatically handles type conversion for numeric values and provides proper error handling for division by zero and missing fields.

warning

Division by zero will cause the processor to fail unless ignore_failure is set to true. Always validate input data or provide proper error handling for cases where the right operand might be zero.

Examples

Basic

Dividing two literal values...

{
"metrics": {}
}
- divide:
field: metrics.ratio
left_operand: "100"
right_operand: "25"

calculates and stores the result:

{
"metrics": {
"ratio": 4
}
}

Field-Based

Dividing values from existing fields...

{
"network": {
"bytes_sent": 15000,
"packets_sent": 30
}
}
- divide:
field: network.bytes_per_packet
left_operand: "network.bytes_sent"
right_operand: "network.packets_sent"

computes the ratio:

{
"network": {
"bytes_sent": 15000,
"packets_sent": 30,
"bytes_per_packet": 500
}
}

Mixed Operands

Combining field value and literal...

{
"disk": {
"used_bytes": 8589934592
}
}
- divide:
field: disk.used_gb
left_operand: "disk.used_bytes"
right_operand: "1073741824"

converts units:

{
"disk": {
"used_bytes": 8589934592,
"used_gb": 8
}
}

Error Handling

Handling potential errors gracefully...

{
"cpu": {
"total_time": 3600,
"idle_time": 1800
}
}
- divide:
field: cpu.active_percentage
left_operand: "cpu.idle_time"
right_operand: "cpu.total_time"
ignore_missing: true
on_failure:
- set:
field: cpu.error
value: "Failed to calculate CPU percentage"

avoids raising exceptions:

{
"cpu": {
"total_time": 3600,
"idle_time": 1800,
"active_percentage": 0.5
}
}