-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstats.sh
executable file
·40 lines (31 loc) · 1.17 KB
/
stats.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/bin/bash
# Extracts metrics from the worker metrics file
# unless provided as input
# then prints out the average value, leaving out the last entry
STATSFILE=$1
# log file does not exist - extract it from the worker's metrics
# and store it in
if [ ! -f "$STATSFILE" ]; then
input=$(ls -t /var/log/storm/workers-artifacts/ | head -n 1)
mkdir -p stats
STATSFILE=stats/$STATSFILE.log
cat /var/log/storm/workers-artifacts/$input/6700/worker.log.metrics | grep average_persec | grep -v received=0.0 > $STATSFILE
fi
total_received=0
count=0
echo "Parsing $STATSFILE"
while IFS= read -r log_line; do
if [ -n "$log_line" ]; then
received_value=$(echo -e "$log_line" | awk -F'received=' '{print $2}' | sed 's/[^0-9.]//g' | awk -F'.' '{print $1}')
if [ -n "$received_value" ]; then
total_received=$(awk "BEGIN{print $total_received + $received_value}")
((count++))
fi
fi
done < <(head -n -1 "$STATSFILE")
if [ "$count" -gt 0 ]; then
average_received=$(awk "BEGIN{print $total_received / $count}")
echo "Average Received value: $average_received"
else
echo "No valid 'received' values found in the log file."
fi