#!/bin/ksh
###
# Capture general database, table and sort monitor elements and high watermarks, for the max number of all agents
# during the online day; this is in response to non-specific performance concerns. Snapshot every 15 minutes.
# This should allow subsequent drill down to more specific performance issues.
# The target tables contain all columns reported by a describe select * from the 2 snapshot table functions. 
#
# Edit the instance and database alias names, and modify the start and stop monitor times for your site.
# The example below assumes an online from 7 am to 6 pm, though in practice the shell may get nobbled 
# by early backups or late starts.
#
# Alex Levy, Sustainable Software Ltd. http://www.sustainablesoftware.net 
# July 2006.
###

#set -x

. /home/instance/sqllib/db2profile

print $0
exec 2>&1
exec 1>/home/instance/admin/monitor/agentcount.log
print $0

while :
do
   db2 "connect to mydbalias" > /dev/null
   db2 "update monitor switches using statement on sort on bufferpool on lock on table on" > /dev/null
   db2 "insert into instance.dbsnap select * from TABLE(snapshot_database('',-1)) as dbsnap "
   db2 "insert into instance.tabsnap select * from TABLE (snapshot_table('',-1)) as tabsnap"
   db2 "commit"            > /dev/null
   db2 "reset monitor all" > /dev/null
   db2 "connect reset"     > /dev/null
#   db2mtrk is an optional extra, as are vmstat,iostat,nfstat ...
#   db2mtrk -i -d -p -v
   if [[ `date +%H` -eq 18 ]]
   then break
   else sleep 900
   fi
done

db2 "terminate" > /dev/null
exec 1>&-
exec 1>&2
