I3status memory in GiB?

Hi
Below I have copied from the i3config man page:
Its all working but I am trying to keep memory units to GiB
I have tried all manner of variations, like with quotes, units not unit, spaces etc etc, etc but am at a loss as is an internet search
Can anyone make the no doubt embarrasingly simple correction for me please?

memory {
        format = "%used"
        unit = Gi
        threshold_degraded = "0.5M"
}

5.11. Memory

Gets the memory usage from system on a Linux system from /proc/meminfo. Other systems are currently not supported.

As format placeholders, total, used, free, available and shared are available. These will print human readable values. It’s also possible to prefix the placeholders with percentage_ to get a value in percent.

It’s possible to define a threshold_degraded and a threshold_critical to color the status bar output in color_degraded or color_bad, if the available memory falls below the given threshold. Possible values of the threshold can be any integer, suffixed with an iec symbol (T, G, M, K). Alternatively, the integer can be suffixed by a percent sign, which then gets evaluated relatively to total memory.

If the format_degraded parameter is given and either the critical or the degraded threshold applies, format_degraded will get used as format string. It acts equivalently to format.

It’s also possible to define the unit for the various format placeholders. As /proc/meminfo returns the memory in kB they will be converted to the given unit. If no unit is given or the auto option is used, the conversion will select the maximum possible unit.

As the converted format placeholder will be a decimal number, the number of decimals can be configured via the decimals option. If no such option is given the converted format placeholder will have one decimal.

As Linux’ meminfo doesn’t expose the overall memory in use, there are multiple methods to distinguish the actually used memory.

Example memory_used_method: memavailable (“total memory” - “MemAvailable”, matches free command)

Example memory_used_method: classical (“total memory” - “free” - “buffers” - “cache”, matches gnome system monitor)

Example order: memory

Example format: %free %available (%used) / %total

Example format: %percentage_used used, %percentage_free free, %percentage_shared shared

Example unit: auto, Ki, Mi, Gi, Ti

Example decimals: 0, 1, 2, 3

Example threshold_degraded: 10%

Example threshold_critical: 5%

Example format_degraded: Memory LOW: %free

Try using:

unit = "GiB"

Looks like the new version of i3status may be buggy. I tried all the units and only using KiB made a switch. Also, it will only show filesystem information for “/” not “/home” or any other mounted filesystem.

1 Like

Try to change the memory module to display total as well. Not sure if i3status converts to “Mib” if it’s less than 1GiB. If total still displays as “MiB”, report to the project’s GH page.

Use @PackRat 's suggestion in your config file.

2 Likes

May also need:

decimal = "3"

to convert any number less that 1GiB. It wasn’t working for me, but if it’s a random bug it may show for @leigh .

2 Likes

Quickly browsed the src code. Looks like “unit” in the config is not picked up.

static int print_bytes_human(char *outwalk, unsigned long bytes, const char *unit, const int decimals) {
    double base = bytes;
    size_t exponent = 0;
    while (base >= BINARY_BASE && exponent < MAX_EXPONENT) {
        if (strcasecmp(unit, iec_symbols[exponent]) == 0) {
            break;
        }

        base /= BINARY_BASE;
        exponent += 1;
    }
    const int prec = decimals > MAX_DECIMALS ? MAX_DECIMALS : decimals;
    return sprintf(outwalk, "%.*f %s", prec, base, iec_symbols[exponent]);
}

I don’t have the env. and am lazy to get one. If you wanna spend a few more mins, use gdb to attach to the process, and dump ctx at i3status.c:831. It shoudl reveal what it holds internally. I dunno if it’s built with optimization. If it is, you may need to rebuild i3status to keep the symbol table.

2 Likes

Thanks both, and specifically:

@PackRat

unit = "GiB"

Did nothing

decimal = "3"

Threw an error exit (1) or similar

@chroot
Double dutch for me but I get the idea you are saying that its a bug &/or the code wont give GiB for less than 1Gib?

Its not the end of the world to have it in MiB, I’m just intrigued

Edit:

unit = "GiB"

doesnt work when < 1GiB, but

unit = "MiB"

does work when > 1 GiB

I just need to try to get rid of the decimal point now

Check the man page, I think:

decimal = "0"

is an option.

1 Like

@PackRat
I had tried that, but without success, and looking at the i3: i3status(1) page couldnt find any mention of decimal option

But, when I looked at the i3status(1) — Arch manual pages page there it was, but its decimals (in the plural)

Both

decimals = "0"

and

decimals = 0

worked!

Thanks!

2 Likes

I use in the i3status.conf

memory {
        format = "Mem: %used | %available"
        threshold_degraded = "1G"
        format_degraded = "MEMORY < %available"
}

or without men available show

memory {
        format = "Mem: %used"
        threshold_degraded = "1G"
}

i do not use i3wm
just wanted to test it
and it work just fine

2 Likes

Well, having that ‘window’ into the CPU and MEM I have come to realise that RAM isnt my problem - its CPU-bound (I just learnt that term)

I looked into htop and then found ps_mem to see that Firefox and Qutebrowser were using about 800 and 510 MiB, respectively for 4 tabs with hte BBC News site and I had around 670 MiB left.
But the CPU was 100% for quite a while until pages loaded

Now looking into over- (right-?) clocking the EeePC as apparently its under-clocked to aid battery life, will start a new thread

Which post to mark as the solution tho? more than one suggestion got me there!

As I said, all learning curve so I might be talking utter nonsense :rofl: