#! /bin/sh
#
# start/stop the system performance monitor daemon
# this version logs output into the root calendar every 15 minutes
#
# set these environment variables to alter thresholds
#Live Rule specific thresholds:
#LR_DISK_SLOW_FD    default=10.0x   derate slow floppys
#LR_DISK_SLOW_CD    default=10.0x   derate slow CDs
#LR_DISK_FLOPPY     default=   fd0  default floppy device
#LR_DISK_CDROM      default=c0t6d0  default CD device
#Pure Rule thresholds
#DISK_BUSY_WARNING  default= 5.0%   ignore less than this
#DISK_BUSY_PROBLEM  default=20.0%   
#DISK_SVC_T_WARNING default=30.0ms    
#DISK_SVC_T_PROBLEM default=50.0ms   
#ENET_INUSE         default=50.0/s  ignore fewer output packets/s
#ENET_COLL_WARNING  default= 5.0%      
#ENET_COLL_PROBLEM  default=10.0%      
#RPCCLIENT_MINCALLS default= 0.0/s  calls per sec for idle
#RPCCLIENT_TIMEOUT  default= 5.0%   calls that timeout
#RPCCLIENT_BADXID   default= 0.0%   timeouts with badxid
#SWAP_WASTE         default=100000KB  more may be a waste
#SWAP_LOTS          default= 10000KB  more is lots
#SWAP_LOW           default=  4000KB  warning LOW to LOTS
#SWAP_NONE          default=  1000KB  danger LOW-NONE, crisis
#RESTIME_LONG       default=600s    No scanning - long res time
#RESTIME_OK         default= 40s    residence time of unref pages
#RESTIME_PROBLEM    default= 20s    pages stolen too quickly
#KMEM_FREEMEM_LOW   default= 64pg   few pages for kernel to use
#RUNQ_IDLE          default= 0.0    Spare CPU capacity
#RUNQ_BUSY          default= 3.0    OK up to this level
#RUNQ_OVERLOAD      default= 5.0    Warning up to this level
#MUTEX_BUSY         default=200.0/s OK up to this level per-CPU
#MUTEX_OVERLOAD     default=400.0/s Warning up to this level
#DNLC_ACTIVE        default=100.0/s minimum activity
#DNLC_WARNING       default=90.0%   warning missrate
#INODE_ACTIVE       default=100.0/s minimum activity
#INODE_WARNING      default=90.0%   warning missrate
#INODE_IPF          default= 0.0%   stolen inodes w/pages frac
#
# use: /opt/RICHPse/examples/mon_cm.se [interval] [calendar]
# default interval is 900 seconds (15min), calendar is whoever runs this file
# but is assumed to be root@nodename

# cm_insert dumps core if HOME is not set
HOME=/
SE=/opt/RICHPse/bin/se
MC=/opt/RICHPse/examples/mon_cm.se
CR=/opt/RICHPse/examples/data/callog.root
export HOME SE MC CR

case "$1" in
 
'start')
	# Start the monitor daemon
	if [ -f /opt/RICHPse/etc/start_mc ]; then
	    if [ -f $MC ] ; then
		echo "Starting performance monitor calendar daemon"
                if [ ! -f /var/spool/calendar/callog.root ] ; then
                    # stop the calendar daemon
                    id=`/bin/ps -e | /bin/grep rpc.cmsd | /bin/awk '{print $1}'`
                    if [ -n "$id" ]; then
                        echo "Stopping rpc.cmsd and creating root calendar"
                        kill $id
                    fi
                    cp $CR /var/spool/calendar/callog.root
                    chgrp daemon /var/spool/calendar/callog.root
                    chmod 460 /var/spool/calendar/callog.root
                fi
                $SE -o- $MC | $SE -t$MC &
	    fi
	fi
	;;
'stop')
	# Stop the monitor daemon
	id=`/bin/ps -ef | /bin/grep mon_cm.se | /bin/grep -v grep | /bin/awk '{print $2}'`
	if [ -n "$id" ]; then
		echo "Stopping performance monitor calendar daemon"
		kill $id
	fi
	;;
esac
