#!/bin/bash
if [ $# -ne 3 ]
then
    echo "error"
    exit 1
fi

nodetool_path=/usr/bin/nodetool

host=$1
jmx_port=$2
column=$3

temp_file=$(tempfile)

$nodetool_path -h $host -p $jmx_port tpstats > $temp_file

if [ $? -ne 0 ]; then
    echo "error"
    rm -f $temp_file
    exit 1
else
    awk_command="BEGIN {sum=0} {sum += \$$column} END {print sum}"
    cat $temp_file | head -16 | tail -15 | awk "$awk_command"
    rm -f $temp_file
fi


