Last active
June 21, 2021 09:48
-
-
Save fritshoogland-yugabyte/c2c6244d4d945e79cafa0aa1423ed498 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/awk -f | |
BEGIN { | |
while ( getline < "/proc/meminfo" > 0 ) | |
all_memory[$1]=$2 | |
for ( type in all_memory ) { | |
if ( type == "MemFree:" || | |
type == "Buffers:" || | |
type == "Dirty:" || | |
type == "SwapCached:" || | |
type == "Writeback:" || | |
type == "WritebackTmp:" || | |
type == "Bounce:" || | |
type == "NFS_Unstable:" || | |
type == "HardwareCurrupted:" || | |
type == "PageTables:" ) | |
selected_memory[type]=all_memory[type] | |
if ( type == "Cached:" ) | |
cached=all_memory[type] | |
if ( type == "Shmem:" ) | |
shmem=all_memory[type] | |
if ( type == "AnonHugePages:" ) | |
anonhugepages=all_memory[type] | |
if ( type == "AnonPages:" ) | |
anonpages=all_memory[type] | |
if ( type == "Mapped:" ) | |
mapped=all_memory[type] | |
if ( type == "KernelStack:" || type == "Slab:" ) | |
kernel_memory+=all_memory[type] | |
if ( type == "MemTotal:" ) | |
total_memory = all_memory[type] | |
if ( type == "MemAvailable:" ) | |
memavailable = all_memory[type] | |
if ( type == "Active:" ) | |
active = all_memory[type] | |
if ( type == "Active(anon):" ) | |
activeanon = all_memory[type] | |
if ( type == "Active(file):" ) | |
activefile = all_memory[type] | |
if ( type == "Inactive:" ) | |
inactive = all_memory[type] | |
if ( type == "Inactive(anon):" ) | |
inactiveanon = all_memory[type] | |
if ( type == "Inactive(file):" ) | |
inactivefile = all_memory[type] | |
} | |
selected_memory["Cached:"]=cached-(shmem+mapped) | |
selected_memory["AnonPages:"]=anonpages-anonhugepages | |
selected_memory["kernel memory"]=kernel_memory | |
for ( type in selected_memory ) | |
total+=selected_memory[type] | |
for ( type in selected_memory ) | |
printf "%-20s %10d kB %7.2f %%\n", type, selected_memory[type], selected_memory[type]/total*100 | |
printf "--------------------------------------------\n" | |
printf "%-20s %10d kB %7.2f %%\n", "total", total, total/total*100 | |
printf "%-20s %10d kB %7.2f %%\n", "MemTotal: ", total_memory, total_memory/total*100 | |
printf "--------------------------------------------\n" | |
printf "%-20s %10d kB %7.2f %%\n", "MemAvailabe: ", memavailable, memavailable/total*100 | |
printf "--------------------------------------------\n" | |
printf "%-20s %10d kB %7.2f %%\n", "Active: ", active, active/total*100 | |
printf " %-19s %10d kB %7.2f %%\n", "Anonymous: ", activeanon, activeanon/total*100 | |
printf " %-19s %10d kB %7.2f %%\n", "File: ", activefile, activefile/total*100 | |
printf "%-20s %10d kB %7.2f %%\n", "Inactive: ", inactive, inactive/total*100 | |
printf " %-19s %10d kB %7.2f %%\n", "Anonymous: ", inactiveanon, inactiveanon/total*100 | |
printf " %-19s %10d kB %7.2f %%\n", "File: ", inactivefile, inactivefile/total*100 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment