c_config.sh 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. #!/bin/sh
  2. #
  3. # Create an example configuration file for symon on a host and print to stdout
  4. # exit on errors, use a sane path and install prefix
  5. #
  6. set -e
  7. PATH=/bin:/usr/bin:/sbin:/usr/sbin
  8. OS=`uname -s`
  9. # verify proper execution
  10. #
  11. if [ $# -ge 3 ]; then
  12. echo "usage: $0 [host] [port]" >&2
  13. exit 1
  14. fi
  15. case "${OS}" in
  16. OpenBSD)
  17. interfaces=`netstat -ni | sed '1,1d;s/^\([a-z]*[0-9]\).*$/\1/g' | uniq`
  18. io=`mount | sed -n '/^\/dev/ s@/dev/\([a-z]*[0-9]\).*@io(\1), @p' | sort -u | tr -d \\\n`
  19. ;;
  20. FreeBSD|NetBSD)
  21. interfaces=`ifconfig -l`
  22. io=`mount | sed -n '/^\/dev/ s@/dev/\([a-z]*[0-9]\).*@io(\1), @p' | sort -u | tr -d \\\n`
  23. ;;
  24. Linux)
  25. interfaces=`ifconfig -a| sed -n '/^[a-z]/ s,\([a-z]*[0-9]\).*,\1,p' | sort -u`
  26. io=`mount | sed -n '/^\/dev/ s@/dev/\([a-z]*[0-9]\).*@io(\1), @p' | sort -u | tr -d \\\n`
  27. ;;
  28. esac;
  29. for i in $interfaces; do
  30. case $i in
  31. bridge*|carp*|enc*|gif*|gre*|lo*|pflog*|pfsync*|ppp*|sl*|tun*|vlan*)
  32. # ignore this interface
  33. ;;
  34. *)
  35. if="if($i), $if"
  36. ;;
  37. esac
  38. done
  39. host=${1:-127.0.0.1}
  40. port=${2:-2100}
  41. cat <<EOF
  42. #
  43. # symon configuration generated by
  44. # `basename $0` $1 $2
  45. #
  46. monitor { $if
  47. $io
  48. cpu(0), mem } stream to $host $port
  49. EOF