1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/linuxdash_ynh.git synced 2024-09-03 19:36:07 +02:00
linuxdash_ynh/sources/server/modules/shell_files/current_ram.sh

15 lines
508 B
Bash
Raw Normal View History

#!/bin/bash
awkCmd=`which awk`
catCmd=`which cat`
grepCmd=`which grep`
memInfoFile="/proc/meminfo"
# References:
# Calculations: http://zcentric.com/2012/05/29/mapping-procmeminfo-to-output-of-free-command/
# Fields: https://www.kernel.org/doc/Documentation/filesystems/proc.txt
memInfo=`$catCmd $memInfoFile | $grepCmd 'MemTotal\|MemFree\|Buffers\|Cached'`
echo $memInfo | $awkCmd '{print "{ \"total\": " ($2/1024) ", \"used\": " ( ($2-($5+$8+$11))/1024 ) ", \"free\": " (($5+$8+$11)/1024) " }" }'