how to modify output of - echo stats | nc <ip> <port>

575 Views Asked by At
TSD_HOST=localhost
TSD_PORT=4242
COLLECTION_INTERVAL=60

nc -z $TSD_HOST $TSD_PORT >/dev/null || exit 13

while :; do
  echo stats || exit
    sleep $COLLECTION_INTERVAL
done | nc $TSD_HOST $TSD_PORT

Output:

tsd.hbase.rpcs 1389058717 2037068142 type=put host=x
tsd.hbase.rpcs 1389058717 0 type=rowLock host=x
tsd.hbase.rpcs 1389058717 17 type=openScanner host=x
tsd.hbase.rpcs 1389058717 29 type=scan host=x
tsd.hbase.rpcs.batched 1389058717 5258656 host=x

Above is the default tcollector script that comes with opentsdb. I want to add an extra tag to every element being printed out; ex:

tsd.hbase.rpcs 1389058717 2037068142 type=put host=x  cluster=y

I want to append cluster=y to every element of stats. But I can't find a good shortcut to do this.

1

There are 1 best solutions below

2
On

Append "| awk '{print $0 " cluster=y"}'" to the end of the "done | nc $TSD_HOST $TSD_PORT" line (or, if you don't want to modify the script, just do tcollector | awk '{print $0 " cluster=y"}).