unit:convert( ) Query Function

Convert values between different units. Such as, 514 ms to 0.514 or sizeInKiB=4 to size=4096.

Troubleshooting note: If the unit begins with a reserved prefix character, try manually setting the unit parameter.

Any unit is supported and the following unit prefixes are converted:

Prefix Factor
Y 1024
Z 1021
E 1018
P 1015
T 1012
G 109
M 106
k 103
h 102
da 101
d 10-1
c 10-2
m 10-3
u 10-6
µ 10-6
n 10-9
p 10-12
f 10-15
a 10-18
z 10-21
y 10-24
Ki 210
Mi 220
Gi 230
Ti 240
Pi 250
Ei 260
Zi 270
Yi 280

If a field contains a value such as 5 kB that should be treated as 5 KiB, set the binary flag.

When the unit is a rate, such as MB/min the rate will be normalized to per second, e.g. B/s.

The following rate convertions are supported: s, sec, m, min, h, hour, d, day, w, week.

Parameters

Name Type Required Default Description
field string Yes The name of the input field.
as string No The output name of the field to set (defaults to the same as the input field).
from string No If the field contains unitless values, specify this parameter to tell which unit the value should be normalized from.
to string No The output field should have the value converted to this unit.
unit string No If specified, the field must end with this unit.
binary bool No false If specified, unit prefixes ‘kMGTPEZY’ will be treated as powers of 1024 instead of 1000.
keepUnit bool No false If specified, the output field will have the normalized unit appended.

field is the unnamed parameter.

Examples

Parses a value into a number by removing the unit. An input event with the field size with the value 5 MB results in the field size having the value 5000000.

unit:convert(size)

Parses a value into a number by removing the unit. An input event with the field size with the value 5 MiB results in the field size having the value 5242880.

unit:convert(size)

Parses a value into a number by removing the unit. An input event with the field size with the value 5 MB results in the field size having the value 5242880.

unit:convert(size, binary=true)

Parses a value into a number by removing the unit. An input event with the field duration with the value 514 us results in the field duration having the value 0.000514.

unit:convert(duration)

Parses a unit less value into a number by manually specifying the input unit. An input event with the field size with the value 234.567 results in the field size having the value 234567.

Internally the value is parsed as {size} {from}, just as if the field had contained the value 234.567 k.

unit:convert(size, from="k")

Parses a value into a number by removing the unit. An input event with the field rate with the value 120 hits/min results in the field rate having the value 2.

Note: since the unit in this case starts with a letter h from the supported prefixes, it will be interpreted as the prefix h (102) and unit its. To enforce that the unit is actually hits, specify the unit parameter.

unit:convert(rate, as="rate", unit="hits")

Converts a number into a value with a unit. An input event with the field size with the value 19886168 results in the field rate having the value 19.886168.

unit:convert(rate, as="rate", to="M")