From 189e796ac0f44b94868fa2224809c3149b6c8671 Mon Sep 17 00:00:00 2001
From: Stephen C Phillips <steve@scphillips.com>
Date: Wed, 21 Feb 2018 09:35:52 +0000
Subject: [PATCH] Improves client error reporting

---
 test/streaming/report.sh | 21 +++++++++++++++++++--
 test/streaming/run.sh    |  3 ++-
 test/streaming/stop.sh   |  3 ++-
 3 files changed, 23 insertions(+), 4 deletions(-)

diff --git a/test/streaming/report.sh b/test/streaming/report.sh
index 351011d..f2a732c 100644
--- a/test/streaming/report.sh
+++ b/test/streaming/report.sh
@@ -1,8 +1,25 @@
 #!/bin/bash
 
+# This script reads stdin.
+# It is used by the run.sh script and receives the output of the cvlc client.
+# It counts the number of times the frame "dropping" error is seen and every 10 times it sends a message to telegraf reporting "another 10" errors.
+
+if [ "$#" -ne 1 ]; then
+    echo "Error: illegal number of arguments: "$#
+    echo "Usage: report.sh <client number>"
+    exit 
+fi
+
 COUNTER=$1
 TELEGRAF=http://localhost:8186
 
+ERR_COUNT=0
 while read line; do
-  curl -i -XPOST "${TELEGRAF}/write?precision=s" --data-binary "vlc,client=${COUNTER} drop_error=1 $(date +%s)" >& /dev/null
-done
+  if [[ $line = *"dropping"* ]]; then
+    ERR_COUNT=$(($ERR_COUNT + 1))
+  fi
+  TEN=$((ERR_COUNT % 10))
+  if [ $TEN -eq 0 ]; then
+    curl -i -XPOST "${TELEGRAF}/write?precision=s" --data-binary "vlc,client=${COUNTER} drop_error=10 $(date +%s)" >& /dev/null
+  fi
+done
\ No newline at end of file
diff --git a/test/streaming/run.sh b/test/streaming/run.sh
index 467b572..3592049 100755
--- a/test/streaming/run.sh
+++ b/test/streaming/run.sh
@@ -47,7 +47,8 @@ STREAM_URI=$2
 COUNTER=0
 MAX_CLIENTS=$3
 while [  $COUNTER -lt $MAX_CLIENTS ]; do
-  cvlc -Vdummy --no-audio $STREAM_URI 2>&1 | tee $TEST_DIR/stdout$COUNTER | grep "dropping" | /home/ubuntu/flame-clmc/test/streaming/report.sh ${COUNTER} &
+  # run cvlc headless, redirect stderr into stdout, pipe that into the report.sh script
+  cvlc -Vdummy --no-audio $STREAM_URI 2>&1 | /home/ubuntu/flame-clmc/test/streaming/report.sh ${COUNTER} &
   sleep 1
   let COUNTER=COUNTER+1 
 done
diff --git a/test/streaming/stop.sh b/test/streaming/stop.sh
index b995389..b332fe3 100755
--- a/test/streaming/stop.sh
+++ b/test/streaming/stop.sh
@@ -1,3 +1,4 @@
 #!/bin/bash
 
-for pid in $(ps -ef | grep "/usr/bin/vlc" | awk '{print $2}'); do kill -9 $pid; done
\ No newline at end of file
+for pid in $(ps -ef | grep "/usr/bin/vlc" | awk '{print $2}'); do kill -9 $pid; done
+# TODO: 'killall vlc' should work: need to test though
\ No newline at end of file
-- 
GitLab