You are not logged in.

#1 2011-12-28 12:02:56

george55
Member
Registered: 2011-08-10
Posts: 68

Show free RAM in i3status [SOLVED]

I am trying to show the available RAM in the i3status bar. However, the manual only provides instructions on how to provide the available hard disk space, not RAM. Ideally, I show the total available RAM in MB or GB. As a newbie, I have two questions about this:

1. Is there a built-in way to display the available RAM in i3status?

2. If I need to use a script that gets the available RAM, what is the best way to do this? I have found several methods, but am wondering what is considered a good practice? For instance, I found the following:

cat /proc/meminfo | grep MemFree

From: http://blog.scoutapp.com/articles/2010/ … oc-meminfo

vmstat 1 2 | sed -n '$ p' | awk '{print $4}'

From: http://www.unix.com/solaris/25527-getti … l-ram.html

With the second script I obtain a number, which I figure is easier to divide and show as MB or GB. However, it appears to be slow. Is this the right way to do so?

Last edited by george55 (2012-12-30 19:43:03)

Offline

#2 2011-12-28 12:47:57

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: Show free RAM in i3status [SOLVED]

awk '/MemFree/ {print $2}' /proc/meminfo

will give you a number (representing kB).

Offline

#3 2012-12-30 19:42:22

george55
Member
Registered: 2011-08-10
Posts: 68

Re: Show free RAM in i3status [SOLVED]

Excellent, thanks!

Offline

#4 2016-08-17 23:08:37

redowk
Member
Registered: 2016-08-17
Posts: 1

Re: Show free RAM in i3status [SOLVED]

sorry for the necrobump but this can actually help someone!

awk can do a bit more work and get you the percentage of used or available memory:

# used memory
awk '/MemTotal/ {memtotal=$2}; /MemAvailable/ {memavail=$2}; END { printf("%.0f", (100- (memavail / memtotal * 100))) }' /proc/meminfo

# available memory
awk '/MemTotal/ {memtotal=$2}; /MemAvailable/ {memavail=$2}; END { printf("%.0f", memavail / memtotal * 100) }' /proc/meminfo

output will be a rounded up percentage of a hole number ex: 50%

Last edited by redowk (2016-08-17 23:11:01)

Offline

#5 2016-08-23 11:02:37

WorMzy
Forum Moderator
From: Scotland
Registered: 2010-06-16
Posts: 11,839
Website

Re: Show free RAM in i3status [SOLVED]

Thanks for sharing, redowk. However, I'm going to take this opportunity to close this old thread.


Sakura:-
Mobo: MSI MAG X570S TORPEDO MAX // Processor: AMD Ryzen 9 5950X @4.9GHz // GFX: AMD Radeon RX 5700 XT // RAM: 32GB (4x 8GB) Corsair DDR4 (@ 3000MHz) // Storage: 1x 3TB HDD, 6x 1TB SSD, 2x 120GB SSD, 1x 275GB M2 SSD

Making lemonade from lemons since 2015.

Offline

Board footer

Powered by FluxBB