# nimon_list_stats
# 1 parameter = the nimon -f output file in InfluxDB Line protocol format
# Suggest nimon -s1 -c1 -f
# nimon_list_stats hostname_datetime.influxlp

file=$1

echo File: $file
echo
echo Tags '- Used to graph a specific host, group by OS or model type etc.'
cat $file | head -1 | awk '{ print $1 }' | sed 's/identity,//' | tr ',' '\n' |  awk '{printf("    %s\n", $1 ) }'

TAGS=$(cat $file | head -1 | sed 's/,/ /' | awk '{ print $2 }')

TMPFILE=/tmp/$0-$$
cat $file | sed 's/'$TAGS'//' | sed 's/   $//' >$TMPFILE

echo
echo 'MEASURES - Trailing "i" means only an integer allowed, otherwise a "string" or floating point number'
echo
for i in $( cat $TMPFILE | awk '{ print $1 }' | sort | uniq )
do
        echo Measure: $(echo $i | tr , ' ' )
        grep ^$i $TMPFILE | tail -1 | \
                sed 's/, / /g' | sed 's/@/+/g' | sed 's/IBM,/IBM/g' | sed 's/ /@/' | \
                awk -F@ '{ print $2 }'  |  tr ' ' '!' |tr ',' '\n' |  \
                awk '{printf("    %s\n", $1 ) }' | tr '!' ' '
done
rm $TMPFILE
