c_config.sh 1.2 KB

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