From: Nicolas Boisselier Date: Thu, 1 Dec 2016 12:18:17 +0000 (+0100) Subject: sys.sh X-Git-Url: https://git.nbdom.net/?a=commitdiff_plain;h=30f9d73b121997587209feaec39bbcde2a247a50;p=nb.git sys.sh --- diff --git a/etc/profile.d/sys.sh b/etc/profile.d/sys.sh index 60afa532..9e5a2415 100644 --- a/etc/profile.d/sys.sh +++ b/etc/profile.d/sys.sh @@ -2,25 +2,41 @@ sys_is_vm() { grep -q ^flags.*\ hypervisor /proc/cpuinfo && echo "This machine is a VM" } +sys_watch() { + export -f sys_activity + watch -d bash -c "sys_activity" +} + sys_activity() { -# if [ -z "$@" ]; then -# export -f $FUNCNAME -# watch -d echo $FUNCNAME _ -# return -# fi + local tmp=/tmp/ [ -d /dev/shm/ ] && tmp=/dev/shm/ tmp="$tmp/$FUNCNAME.$$" netstat -autpn > $tmp.netstat echo 'Load:' - w + w | head -1 + echo echo 'IO:' - iostat -c -m -d -x `df -hT -x tmpfs|perl -ane 'm:^/: and print $F[0]."\n"'` + iostat -c -m -d -x `df -hT -x tmpfs|perl -ane 'm:^/: and print $F[0]."\n"'` | tail -n +3 | grep -vFx ''| sed 's/^/ /' + echo + + echo 'Mem:' + free -hm | sed 's/^/ /' + echo + + echo 'Top ips:' + cat "$tmp.netstat" | tail -n +2 | awk '$5~/^[0-9]/{gsub(/:.*/,"",$5);print $5}' | sort | uniq -c| sed 's/^ *//'|sort -nr -k 1 |head | sed 's/^/ /' + echo + + echo 'dmeg:' + dmesg -T | tail | sed 's/^/ /' + echo - echo 'Top ip activity:' - cat "$tmp.netstat" | tail -n +2 | awk '$5~/^[0-9]/{gsub(/:.*/,"",$5);print $5}' | sort | uniq -c| sed 's/^ *//'|sort -nr -k 1 |head + echo 'auth:' + tail /var/log/auth.log | sed 's/^/ /' + echo rm -rf "$tmp"* }