From 90dcad7e6f4920187a9675c961feeef931ce4682 Mon Sep 17 00:00:00 2001 From: m0duspwnens Date: Fri, 18 Dec 2020 11:00:24 -0500 Subject: [PATCH] make sure timestamp on steno log line has changed so we dont snapshot the drop% --- salt/telegraf/scripts/stenoloss.sh | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/salt/telegraf/scripts/stenoloss.sh b/salt/telegraf/scripts/stenoloss.sh index d078284a4..9cdf7f99c 100644 --- a/salt/telegraf/scripts/stenoloss.sh +++ b/salt/telegraf/scripts/stenoloss.sh @@ -15,7 +15,6 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . - APP=stenoloss lf=/tmp/$APP-pidLockFile # create empty lock file if none exists @@ -25,7 +24,22 @@ read lastPID < $lf [ ! -z "$lastPID" -a -d /proc/$lastPID ] && exit echo $$ > $lf -# Get the data -DROP=$(tac /var/log/stenographer/stenographer.log | grep -m1 drop | awk '{print $14}' | awk -F "=" '{print $2}') +TSFILE=/var/log/telegraf/laststenodrop.log +if [ -f "$TSFILE" ]; then + LASTTS=$(cat $TSFILE) +else + LASTTS=0 +fi -echo "stenodrop drop=$DROP" +# Get the data +LOGLINE=$(tac /var/log/stenographer/stenographer.log | grep -m1 drop) +CURRENTTS=$(echo $LOGLINE | awk '{print $1}') + +if [[ "$CURRENTTS" != "$LASTTS" ]]; then + DROP=$(echo $LOGLINE | awk '{print $14}' | awk -F "=" '{print $2}') + echo $CURRENTTS > $TSFILE +else + DROP=0 +fi + +echo "stenodrop drop=$DROP" \ No newline at end of file