You are not logged in.

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

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

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,430

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: 38

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 Today 11:02:37

WorMzy
Forum Moderator
From: Scotland
Registered: 2010-06-16
Posts: 5,355

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: ASUS P8Z77-V PRO // Processor: Intel Core i7-3770K 3.4GHz // GFX: nVidia GeForce GTX 970 Ti // RAM: 32GB (4x 8GB) Corsair DDR3 (@ 2133MHz) // Storage: 1x 3TB Seagate SATAII 5x 1TB Samsung SATAII, 2x 120GB Corsair SSD

Online

Board footer

Powered by FluxBB