#! /bin/sh
#
# Copyright (c) 2007 Aconex.  All Rights Reserved.
# 
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the
# Free Software Foundation; either version 2 of the License, or (at your
# option) any later version.
# 
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
# or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
# for more details.
# 
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
#
# Install the jstat PMDA and/or PMNS
#

# Get standard environment
. /etc/pcp.env

# Get the common procedures and variable assignments
#
. $PCP_SHARE_DIR/lib/pmdaproc.sh

# The name of the PMDA
#
iam=jstat

# Using libpcp_pmda.so.2 and PMDA_INTERFACE_3
#
pmda_interface=3

# Do it
#
pmdaSetup

if $do_pmda
then

    dso_opt=false
    socket_opt=false
    pipe_opt=true

    java_home="$JAVA_HOME"
    while true
    do
	$PCP_ECHO_PROG $PCP_ECHO_N 'JAVA_HOME directory ['"$java_home"'] '"$PCP_ECHO_C"
	read ans
	[ -z "$ans" ] && break
	if [ -d "$ans" ]
	then
	    java_home="$ans"
	    break
	fi
	echo "Error: \"$ans\" is not a directory"
    done

    jstat_path="$java_home/bin"
    while true
    do
	$PCP_ECHO_PROG $PCP_ECHO_N 'jstat directory ['"$jstat_path"'] '"$PCP_ECHO_C"
	read ans
	[ -z "$ans" ] && break
	if [ -d "$ans" ]
	then
	    jstat_path="$ans"
	    break
	fi
	echo "Error: \"$ans\" is not a directory"
    done

    args="$args -P $jstat_path -J $java_home"

    refresh=5
    $PCP_ECHO_PROG $PCP_ECHO_N 'Seconds between refreshes ['"$refresh"'] '"$PCP_ECHO_C"
    read ans
    [ ! -z "$ans" ] && args="$args -r $ans"
    echo
fi

pmdaInstall

exit 0
