This repository has been archived on 2023-08-20. You can view files and clone it, but cannot push or open issues or pull requests.
spark-art-dashboard/log-provider.sh
Diogo Cordeiro 838cc1d950 Limit the log size so that dashboard charts are not overloaded
Added configuration constants
This script is designed to be ran by Dash (which is faster than Bash)
2018-10-03 03:10:49 +01:00

27 lines
655 B
Bash
Executable File

#!/bin/sh
# CSV file name
FILENAME=$(ls stats-* | tail -n 1)
# chunk file name
CHUNK_FILENAME="current-log-provider-chunk.csv"
# number of log lines for chunk
N=100
# server port
PORT=4870
# CSV header
header=$(head -n 1 "$FILENAME")
while true; do
# We don't want repeated headers
if [ $(wc -l < "$FILENAME") -gt "$N" ]; then
{ echo "$header"; tail -n "$N" $FILENAME; } > "$CHUNK_FILENAME"
else
cp -f -- "$FILENAME" "$CHUNK_FILENAME"
fi
{ echo -ne "HTTP/1.0 200 OK\r\nContent-Length: $(wc -c <"current-log-provider-chunk.csv")\r\nAccess-Control-Allow-Origin: *\r\n\r"; cat "current-log-provider-chunk.csv"; } | nc -v -l -p "$PORT"
done