eewatch 1.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. #!/bin/bash
  2. . <(ffoom init)
  3. ffoo import core
  4. ffoo import recon
  5. FFOO_DEBUG=false
  6. interval=2
  7. report_limits() {
  8. echo "ulimit -m:$(ulimit -m)"
  9. echo "ulimit -Sm:$(ulimit -Sm)"
  10. echo "ulimit -Hm:$(ulimit -Hm)"
  11. echo "ulimit -n:$(ulimit -n)"
  12. echo "ulimit -Sn:$(ulimit -Sn)"
  13. echo "ulimit -Hn:$(ulimit -Hn)"
  14. }
  15. report_on_pids() {
  16. local pid
  17. for pid in "$@";
  18. do
  19. echo "$pid:name:$(ps -p $pid -o comm=)"
  20. echo "$pid:rss:$(ps -p $pid -o rss=)"
  21. echo "$pid:files:$(lsof -p $pid | wc -l)"
  22. done
  23. }
  24. usage() {
  25. usage_is "[-i INTERVAL] [-d] -p PID[,PID]..." \
  26. "[-i INTERVAL] [-d] -r REGEX[,REGEX]..."
  27. }
  28. regexes=""
  29. pids=""
  30. while true;
  31. do
  32. case $1 in
  33. -i|--interval)
  34. interval=$2
  35. shift 2
  36. ;;
  37. -d|--debug)
  38. FFOO_DEBUG=true
  39. shift 1
  40. ;;
  41. -r|--regexes)
  42. regexes=$2
  43. shift 2
  44. ;;
  45. -p|--pids)
  46. pids=$2
  47. shift 2
  48. ;;
  49. "")
  50. if test -z "$regexes" && test -z "$pids";
  51. then usage;
  52. else break;
  53. fi
  54. ;;
  55. *)
  56. usage
  57. ;;
  58. esac
  59. done
  60. pids=$(tr "," " " <<<"$pids")
  61. regexes=$(tr "," " " <<<"$regexes")
  62. report_limits
  63. while true;
  64. do
  65. # append PIDS from regexes to pids from command line
  66. current_pids="$pids $(pids_matching $regexes)"
  67. debug -v current_pids
  68. report_on_pids $current_pids
  69. sleep $interval
  70. done