c_config.sh 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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. cpu="cpu(0),"
  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. cpu=`sysctl dev.cpu | grep '%desc' | sed -n 's/dev.cpu.\([0-9]*\).*$/cpu(\1), /p'`
  25. ;;
  26. Linux)
  27. interfaces=`ifconfig -a| sed -n '/^[a-z]/ s,\([a-z]*[0-9]\).*,\1,p' | sort -u`
  28. io=`mount | sed -n '/^\/dev/ s@/dev/\([a-z]*[0-9]\).*@io(\1), @p;s@/dev/\(x[a-z]\+[0-9]*\).*@io(\1), @p' | sort -u | tr -d \\\n`
  29. cpu=`cat /proc/cpuinfo | sed -n '/^processor/ s@[^:]\+: \([0-9]\+\)@cpuiow\(\1\), @p' | sort -u | tr -d \\\n`
  30. ;;
  31. esac;
  32. for i in $interfaces; do
  33. case $i in
  34. bridge*|carp*|enc*|gif*|gre*|lo*|pflog*|pfsync*|ppp*|sl*|tun*|vlan*)
  35. # ignore this interface
  36. ;;
  37. *)
  38. if="if($i), $if"
  39. ;;
  40. esac
  41. done
  42. host=${1:-127.0.0.1}
  43. port=${2:-2100}
  44. cat <<EOF
  45. #
  46. # symon configuration generated by
  47. # `basename $0` $1 $2
  48. #
  49. monitor { ${if}${io}${cpu}mem } stream to $host $port
  50. EOF