Skip to main content

Data Size

Parse Data Analysis

Synopsis

Parses human-readable data sizes (e.g., "1kb") to byte values.

Schema

- data_size:
field: <ident>
target_field: <ident>
output_format: <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-Source field containing human-readable data size
target_fieldNSame as fieldTarget field to store parsed byte value
output_formatNbytesbytes writes the byte count as a number; detailed writes an object. Any other value fails the processor
descriptionN-Explanatory note
ifN-Condition to run
ignore_failureNfalseContinue processing if parsing fails
ignore_missingNfalseSkip processing if referenced field doesn't exist
on_failureN-See Handling Failures
on_successN-See Handling Success
tagN-Identifier
disabledNfalseWhen true, the processor is skipped and the event continues to the next one. Lets you take a processor out of the path without removing its configuration

Details

Converts human-readable data size strings to numerical byte values. Supports B, KB, MB, GB, TB and PB, and the binary equivalents KiB, MiB, GiB, TiB and PiB. Long forms are accepted too — megabyte, megabytes, mbyte, mbytes and their siblings all normalize.

The processor recognizes 1.5GB, 512 MB, 2TB and a bare number, which is read as bytes. Decimal units are 1000-based and binary units 1024-based. The source field must be a string — a numeric field fails with field is not a string. A fractional result is rounded to the nearest byte.

note

The processor supports both decimal units (KB, MB, GB using 1000-based calculations) and binary units (KiB, MiB, GiB using 1024-based calculations). Units are case-insensitive.

When output_format is detailed the processor writes an object with five keys — bytes, value, unit, unit_type and original_size. unit is the normalized spelling (GiB, not gib), and unit_type is binary or decimal.

warning

If the input string cannot be parsed as a valid data size, the processor will fail unless ignore_failure is set to true. Invalid units or malformed size strings will trigger errors.

Examples

Basic Size Parsing

Converting readable size to bytes...

{
"file_size": "1.5GB"
}
- data_size:
field: file_size
target_field: size_bytes

converts to byte value:

{
"file_size": "1.5GB",
"size_bytes": 1500000000
}

Binary Units

Using binary (1024-based) units...

{
"memory_usage": "512 MiB"
}
- data_size:
field: memory_usage
target_field: memory_bytes

calculates using 1024-based units:

{
"memory_usage": "512 MiB",
"memory_bytes": 536870912
}

Detailed Output

Getting detailed parsing information...

{
"disk_space": "2.5 TB"
}
- data_size:
field: disk_space
output_format: detailed
target_field: disk_info

returns detailed breakdown:

{
"disk_space": "2.5 TB",
"disk_info": {
"bytes": 2500000000000,
"value": 2.5,
"unit": "TB",
"unit_type": "decimal",
"original_size": "2.5 TB"
}
}

Mixed Case Units

Processing case-insensitive units...

{
"bandwidth": "100 mb"
}
- data_size:
field: bandwidth

replacing the source value, since target_field defaults to field:

{
"bandwidth": 100000000
}