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

nodetool_path=/usr/bin/nodetool
host=$1
jmx_port=$2

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
    cat $temp_file | tail -6 | awk 'BEGIN {sum=0} {sum+=$2} END {print sum}'
    rm -f $temp_file
fi

