agent_based_api.v1.render

The “render” namespace adds functions to render values in a human readable way.

All of the render functions take a single numerical value as an argument, and return a string.

date(epoch)

Render seconds since epoch as date

Example

>>> date(None)
'never'
>>> _ = date(1606721022)

The latter will return something like ‘Nov 30 2020’, depending on the time zone.

Return type

str

datetime(epoch)

Render seconds since epoch as date and time

Example

>>> datetime(None)
'never'
>>> _ = datetime(1606721022)

The latter will return something like ‘Nov 30 2020 07:23:42’, depending on the time zone.

Return type

str

timespan(seconds)

Render a time span in seconds

Example

>>> timespan(1606721)
'18 days 14 hours'
>>> timespan(0.0001)
'100 microseconds'
Return type

str

disksize(bytes_)

Render a disk size in bytes using an appropriate SI prefix

Example

>>> disksize(1024)
'1.02 kB'
Return type

str

bytes(bytes_)

Render a number of bytes using an appropriate IEC prefix

Example

>>> bytes(1024**2)
'1.00 MiB'
Return type

str

filesize(bytes_)

Render a file size in bytes

Example

>>> filesize(12345678)
'12,345,678 B'
Return type

str

frequency(hertz)

Render a frequency in hertz using an appropriate SI prefix

Example

>>> frequency(1e10 / 3.)
'3.33 GHz'
Return type

str

networkbandwidth(octets_per_sec)

Render network bandwidth using an appropriate SI prefix

Return type

str

nicspeed(octets_per_sec)

Render NIC speed using an appropriate SI prefix

Example

>>> nicspeed(1050)
'8.4 kBit/s'
Return type

str

iobandwidth(bytes_)

Render IO-bandwith using an appropriate SI prefix

Example

>>> iobandwidth(128)
'128 B/s'
Return type

str

percent(percentage)

Render percentage

Example

>>> percent(23.4203245)
'23.42%'
>>> percent(0.003)
'<0.01%'
>>> percent(-0.003)
'-0.00%'
Return type

str