From aea6024d1bf3d3d42a6778de12d730adf4de114b Mon Sep 17 00:00:00 2001 From: Horus3 Date: Wed, 25 Nov 2015 18:41:06 +0100 Subject: Rename checkswap -> swap. Inline resources in respondtime.sh. --- bin/checkswap | 75 -------------------------------------------------- bin/nwhois.sh | 0 bin/respondtime.sh | 23 ++++++++++++---- bin/swap | 75 ++++++++++++++++++++++++++++++++++++++++++++++++++ resources/curlinfo.txt | 8 ------ 5 files changed, 92 insertions(+), 89 deletions(-) delete mode 100755 bin/checkswap mode change 100644 => 100755 bin/nwhois.sh create mode 100755 bin/swap delete mode 100644 resources/curlinfo.txt diff --git a/bin/checkswap b/bin/checkswap deleted file mode 100755 index b3a9a31..0000000 --- a/bin/checkswap +++ /dev/null @@ -1,75 +0,0 @@ -#!/bin/bash - -# order by -by="swap" - -# reverse sort -rev="r" - -if [ ! -z "$1" ]; then - case "$1" in - -s|--swap|swap) - by="swap" - shift - ;; - -m|--memory|mem|memory) - by="memory" - shift - ;; - -n|--name|-p|--process|--program|name|proc|process) - by="name" - rev="" - shift - ;; - -h|--help|help) - echo "Statistics about memory and swap usage from all running processes." - echo "Usage: $0 [OPTION]" - echo " swap sort by swap usage (default)" - echo " memory sort by memory usage" - echo " name sort by process name" - echo " help print this help message" - exit 0 - ;; - *) - echo "Unrecognized option \"$1\"" >&2 - echo "Try \"-h\" instead." - exit 1 - esac -fi - -echo "Check memory and swap usage for all programs sorted by $by." -echo "$(tput setaf 1)Attention! The reported memory usage is just the $(tput bold)virtual$(tput sgr0) $(tput setaf 1)usage, not the $(tput bold)real$(tput sgr0) $(tput setaf 1)one." -echo "Read more about this on Wikipedia. $(tput bold)https://en.wikipedia.org/wiki/Virtual_memory$(tput sgr0)" -echo "" - -# loop over all running programs -for CMD in $(top -bn1 | tail -n +8 | grep -v $(basename "$0") | awk '{print $12}' | sort | uniq) -do - swap_count=0 - mem_count=0 - - # loop over all pids and check for 'VmSize' and 'VmSwap' state in /proc/$PID/status - for tmp in $( for PID in $(pgrep $CMD 2>/dev/null); do grep -E 'Vm(Size|Swap)' /proc/$PID/status 2>/dev/null | paste - - | awk '{print $2 "|" $5}'; done ) - do - mem_count=$(($mem_count+$(echo $tmp | cut -d\| -f1))) - swap_count=$(($swap_count+$(echo $tmp | cut -d\| -f2))) - done - - # programs swap or memory use is not null - if [ $swap_count -gt 0 ] || [ $mem_count -gt 0 ] - then - case "$by" in - swap) - echo "$swap_count kB (Swap): $CMD $mem_count kB (Memory)" - ;; - memory) - echo "$mem_count kB (Memory): $CMD $swap_count kB (Swap)" - ;; - name) - echo "$CMD: $mem_count kB (Memory) $swap_count kB (Swap)" - ;; - esac - fi - -# sorting and formatting output -done | sort -k1 -t\ -h${rev} | column -t diff --git a/bin/nwhois.sh b/bin/nwhois.sh old mode 100644 new mode 100755 diff --git a/bin/respondtime.sh b/bin/respondtime.sh index de0731b..6d5b9e4 100755 --- a/bin/respondtime.sh +++ b/bin/respondtime.sh @@ -1,16 +1,27 @@ #!/bin/bash # use cURL to measure the time until the webpage loads -CURLINFOTEXT="$(dirname $0)/../resources/curlinfo.txt" +CURLINFOTEXT=" + time_namelookup: %{time_namelookup} -if [ ! -f "$CURLINFOTEXT" ]; then - echo "$(tput setaf 1)$(tput bold)Failure. $(tput sgr0)No Info Text for cURL given." 1>&2 - exit 1 -fi + time_connect: %{time_connect} + + time_appconnect: %{time_appconnect} + + time_pretransfer: %{time_pretransfer} + + time_redirect: %{time_redirect} + + time_starttransfer: %{time_starttransfer} + + ---------- + + time_total: %{time_total} +" if [ -z "$1" ]; then echo "$(tput setaf 1)$(tput bold)Failure. $(tput sgr0)Missing URL or Hostname" 1>&2 exit 1 fi -curl -w "@$CURLINFOTEXT" -o /dev/null -s "$1" +curl -w "$CURLINFOTEXT" -o /dev/null -s "$1" diff --git a/bin/swap b/bin/swap new file mode 100755 index 0000000..b3a9a31 --- /dev/null +++ b/bin/swap @@ -0,0 +1,75 @@ +#!/bin/bash + +# order by +by="swap" + +# reverse sort +rev="r" + +if [ ! -z "$1" ]; then + case "$1" in + -s|--swap|swap) + by="swap" + shift + ;; + -m|--memory|mem|memory) + by="memory" + shift + ;; + -n|--name|-p|--process|--program|name|proc|process) + by="name" + rev="" + shift + ;; + -h|--help|help) + echo "Statistics about memory and swap usage from all running processes." + echo "Usage: $0 [OPTION]" + echo " swap sort by swap usage (default)" + echo " memory sort by memory usage" + echo " name sort by process name" + echo " help print this help message" + exit 0 + ;; + *) + echo "Unrecognized option \"$1\"" >&2 + echo "Try \"-h\" instead." + exit 1 + esac +fi + +echo "Check memory and swap usage for all programs sorted by $by." +echo "$(tput setaf 1)Attention! The reported memory usage is just the $(tput bold)virtual$(tput sgr0) $(tput setaf 1)usage, not the $(tput bold)real$(tput sgr0) $(tput setaf 1)one." +echo "Read more about this on Wikipedia. $(tput bold)https://en.wikipedia.org/wiki/Virtual_memory$(tput sgr0)" +echo "" + +# loop over all running programs +for CMD in $(top -bn1 | tail -n +8 | grep -v $(basename "$0") | awk '{print $12}' | sort | uniq) +do + swap_count=0 + mem_count=0 + + # loop over all pids and check for 'VmSize' and 'VmSwap' state in /proc/$PID/status + for tmp in $( for PID in $(pgrep $CMD 2>/dev/null); do grep -E 'Vm(Size|Swap)' /proc/$PID/status 2>/dev/null | paste - - | awk '{print $2 "|" $5}'; done ) + do + mem_count=$(($mem_count+$(echo $tmp | cut -d\| -f1))) + swap_count=$(($swap_count+$(echo $tmp | cut -d\| -f2))) + done + + # programs swap or memory use is not null + if [ $swap_count -gt 0 ] || [ $mem_count -gt 0 ] + then + case "$by" in + swap) + echo "$swap_count kB (Swap): $CMD $mem_count kB (Memory)" + ;; + memory) + echo "$mem_count kB (Memory): $CMD $swap_count kB (Swap)" + ;; + name) + echo "$CMD: $mem_count kB (Memory) $swap_count kB (Swap)" + ;; + esac + fi + +# sorting and formatting output +done | sort -k1 -t\ -h${rev} | column -t diff --git a/resources/curlinfo.txt b/resources/curlinfo.txt deleted file mode 100644 index fa9ec7f..0000000 --- a/resources/curlinfo.txt +++ /dev/null @@ -1,8 +0,0 @@ - time_namelookup: %{time_namelookup}\n - time_connect: %{time_connect}\n - time_appconnect: %{time_appconnect}\n - time_pretransfer: %{time_pretransfer}\n - time_redirect: %{time_redirect}\n - time_starttransfer: %{time_starttransfer}\n - ----------\n - time_total: %{time_total}\n -- cgit v1.2.3