blob: eb9ffde0721c698b538c91b8abe1aea37272e799 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
#!/usr/bin/awk -f
function getvar(label) {
while (getline < meminfo && $1 != label":");
return $2
}
BEGIN {
meminfo="/proc/meminfo"
# Make sure these are in order of the output of /proc/meminfo
memtotal = getvar("MemTotal")
memfree = getvar("MemFree")
buffers = getvar("Buffers")
cached = getvar("Cached")
shmem = getvar("Shmem")
sreclaimable = getvar("SReclaimable")
# Htop calculations
totalused = memtotal - memfree
totalcached = cached + sreclaimable - shmem
noncachenonbuf = totalused - (buffers + totalcached)
# Print % of memory used
print int((noncachenonbuf * 100) / memtotal)"%"
}
#BEGIN {
# cmd="free -b"
# cmd | getline
# cmd | getline
# print int($3*100/$2)"%"
#}
##awk '{ if(!total){ total = $2 } else if(!free){ free = $2 } else{ exit } } END{ print int(((total-free)*100)/total)"%" }' /proc/meminfo
|