Skip to content

Instantly share code, notes, and snippets.

@kidmose
Last active August 29, 2015 14:20
Show Gist options
  • Save kidmose/add104a37c213be72654 to your computer and use it in GitHub Desktop.
Save kidmose/add104a37c213be72654 to your computer and use it in GitHub Desktop.
Simple linux ressource usage logging
#!/bin/bash
# timestamp
echo -n `date "+%d/%m/%Y %H:%M:%S"` ";"
# cpu
echo -n `top -b -n1 | grep "Cpu(s)" | awk '{print $2 + $4}'` ";"
free > /tmp/free
# Used RAM
echo -n `cat /tmp/free | grep Mem | sed -e "s/\s\{1,\}/ /g" | cut -f3 -d' '` ";"
# RAM used by kernel for caching
echo -n `cat /tmp/free | grep cache: | sed -e "s/\s\{1,\}/ /g" | cut -f4 -d' '` ";"
rm /tmp/free
# hdd
echo `df -lh | awk '{if ($6 == "/") { print $5 }}' | head -1 | cut -d'%' -f1` ";"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment