Formats a duration into a human readable string.

Function Summary
SignatureformatDuration([as], field, [from], [precision])
Function TypeTransformation,Field Computation
Parameters for formatDuration()
ParameterTypeInterpreted TypeRequiredDefault ValueDescription
asstringfieldnameoptional[a]   The output name of the field to set (defaults to the same as the input field).
field[b]stringfieldnamerequired   The name of the input field. Must be an integer.
fromlonglongoptional[a] ms Magnitude of the input field.
    Values
    dDays
    hHours
    mMinutes
    msMilliseconds
    nsNanoseconds
    sSeconds
    usMicroseconds
precisionintegerintegeroptional[a] 0 Number of units to use in the output.

[a] Optional parameters use their default value unless explicitly set.

[b] The parameter name field can be omitted.

Hide omitted argument names for this function

Show omitted argument names for this function

formatDuration() Function Operation

Formats a duration into a string. For example, an input event with the field duration with the value 23452553 with a default interpretation of the source value as milliseconds results in the field duration having the value 6h30m52s553ms.

logscale
formatDuration(duration)

Important

The value of the field being formatted must be an integer. If you have a floating point input value, the value will not be converted. To fix, use round() or format() to create an integer value.

Click + next to an example below to get the full details.

Format Duration Into Human Readable String

Format a duration into a human readable string using the formatDuration() function

Query
logscale
formatDuration(duration, precision=3)
Introduction

In this example, the formatDuration() function is used to format the sequences of decimal numbers into a human readable string with limited precision. Note that the value of the field being formatted must always be an integer.

Step-by-Step
  1. Starting with the source repository events.

  2. logscale
    formatDuration(duration, precision=3)

    Formats a duration into a string. The duration field contains the value in milliseconds.

    For example, an input event with the field duration with the value 23452553 with a default interpretation of the source value as milliseconds, results in the field duration having the value 6h30m52s553ms.

    The optional precision parameter specifies the number of time units to include. In this example, precision equals 3, which means, that it shows three units: hours, minutes, and seconds. If precision=2 is used, it may show 6h30m instead.

  3. Event Result set.

Summary and Results

The query is used to format the sequences of decimal numbers into a human readable string to improve readability of log entries with duration fields. The value of the field being formatted must always be an integer. If not an integer, you can use round() or format() to create an integer value.

It is also possible to use the formatDuration() function in combination with eval() to create a new formatted field:

formatDuration(processingTime, precision=3)
|eval(formattedDuration = formatDuration(duration))