Created
April 2, 2019 07:31
-
-
Save lakuapik/ce26e8283cf3d0b08ae315380493d98a to your computer and use it in GitHub Desktop.
Stat Log Linux
This file contains hidden or 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
#!/bin/bash | |
# DateTime | |
now=`date +"%Y/%m/%d %H:%M:%S"` | |
# Memory Total | |
mem_total=`grep 'MemTotal' /proc/meminfo | awk '{print $2}'` | |
mem_total=$(expr $mem_total / 1024) #KB to MB | |
# Memory Used | |
mem_used=`grep 'Active:' /proc/meminfo | awk '{print $2}'` | |
mem_used=$(expr $mem_used / 1024) #KB to MB | |
# Memory percentage | |
mem_percent=`awk "BEGIN{print $mem_used / $mem_total * 100}"` | |
mem_percent="$mem_percent%" | |
# CPU core | |
cpu_core=`nproc` | |
# CPU Used | |
# https://stackoverflow.com/questions/9229333/how-to-get-overall-cpu-usage-e-g-57-on-linux | |
cpu_used=`grep 'cpu ' /proc/stat | awk '{usage=($2+$4)*100/($2+$4+$5)} END {print usage "%"}'` | |
# Disk | |
disk_total=`df -BM | grep /xvd | awk '{print $2}'` | |
disk_available=`df -BM | grep /xvd | awk '{print $3}'` | |
disk_percent=`df -BM | grep /xvd | awk '{print $5}'` | |
echo "$now, ${mem_used}M, ${mem_total}M, $mem_percent, $cpu_used, $disk_available, $disk_total, $disk_percent" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment