Back to Netdata

Sizes

src/libnetdata/parsers/sizes.md

2.10.32.9 KB
Original Source

Data Sizes in Netdata

Netdata provides a flexible system for specifying and formatting data sizes, used in various configurations and operations such as disk space management, and memory usage. This system allows users to specify data sizes in a human-readable format using multiple units from bytes to terabytes, supporting both binary (base-2) and decimal (base-10) standards. All units are UCUM-based for consistency and clarity.

Supported Size Units

The following table lists all supported units and their corresponding values:

SymbolDescriptionValueBaseFormatter
BBytes1B-Yes
kKilobytes1000BBase-10No
KKilobytes1000BBase-10No
KBKilobytes1000BBase-10No
KiBKibibytes1024BBase-2Yes
MMegabytes1000KBase-10No
MBMegabytes1000KBase-10No
MiBMebibytes1024KiBBase-2Yes
GGigabytes1000MBase-10No
GBGigabytes1000MBase-10No
GiBGibibytes1024MiBBase-2Yes
TTerabytes1000GBase-10No
TBTerabytes1000GBase-10No
TiBTebibytes1024GiBBase-2Yes
PPetabytes1000TBase-10No
PBPetabytes1000TBase-10No
PiBPebibytes1024TiBBase-2Yes

Size Expression Format

Netdata allows users to express sizes using a number followed by a unit, such as 500MiB (500 Mebibytes), 1GB (1 Gigabyte), or 256K (256 Kilobytes).

  • Case Sensitivity: Note that the parsing of units is case-sensitive.

Size Formatting

Netdata formats a numeric size value (in bytes) into a human-readable string with an appropriate unit. The formatter's goal is to select the largest unit that can represent the size exactly, using up to two fractional digits. If two fractional digits are not enough to precisely represent the byte count, the formatter will use a smaller unit until it can accurately express the size, eventually falling back to bytes (B) if necessary.

When formatting, Netdata prefers Base-2 units (KiB, MiB, GiB, etc.).

  • Examples of Size Formatting:
    • 10,485,760 bytes is formatted as 10MiB (10 Mebibytes).
    • 1,024 bytes is formatted as 1KiB (1 Kibibyte).
    • 1,500 bytes remains formatted as 1500B because it cannot be precisely represented in KiB or any larger unit using up to two fractional digits.

Example Size Expressions

Here are some examples of valid size expressions:

  1. 1024B: 1024 bytes.
  2. 1KiB: 1024 bytes.
  3. 5MiB: 5 mebibytes (5 * 1024 * 1024 bytes).