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