Last active
November 19, 2017 01:01
-
-
Save ostinelli/449632408c5f48a3331a to your computer and use it in GitHub Desktop.
Monitor server CPU and memory.
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/env bash | |
# settings | |
OUTPUT_FILE=monitor.csv | |
# build command | |
cmd="" | |
cpu_headers="" | |
for (( i=4; i<=$(nproc)+4; i++ )) | |
do | |
cmd="${cmd}NR==$i{printf \"%.1f,\", 100-\$13}" | |
done | |
cmd="echo -n \`date +%s\`, && mpstat -P ALL 1 1 | awk '${cmd}' && uptime | awk 'NR==1{printf \"%.2f,\", \$8}' && free | awk 'NR==2{printf \"%s,%s\n\", \$3, \$2}'" | |
# print headers | |
cpu_headers="" | |
for (( i=1; i<=$(nproc); i++ )) | |
do | |
cpu_headers="${cpu_headers}cpu_$i," | |
done | |
echo "epoch,cpu_all,${cpu_headers}load,mem_used,mem_total"> $OUTPUT_FILE | |
# loop data | |
while true; do (eval $cmd) >> $OUTPUT_FILE; done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment