Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit c0e5e2a

Browse files
committedAug 20, 2015
Changed log message date/time tokenisation to use sed instead of awk
1 parent 4ac5040 commit c0e5e2a

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed
 

‎count_entries_per_hour.sh

+6-4
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,25 @@
44
# in the Cassandra system.log.
55
#
66
# Author Erick Ramirez, 2015 Mar 31
7+
# Updated by Erick Ramirez, 2015 Aug 20 - changed the way date/time is getting tokenized to account for variations in log entries
78
#
89

9-
#q=ParNew
10-
#for node in *; do echo "===== $node ====="; log=$node/system-20150317.log; for x in `grep "$q" $log | awk '{print $4}' | cut -d: -f1 | sort -u`; do y=`grep "$q" $log | grep -c "2015-03-17 $x:"`; echo "${x}:00 - $y"; done; echo ""; done
11-
1210
# validate arguments
1311
if [ "$#" -ne 2 ]
1412
then
1513
echo "ERROR - Usage: `basename $0` <query_string> <system_log>"
1614
exit 1
15+
elif [ ! -r $2 ]
16+
then
17+
echo "ERROR - Log file [$2] not readable"
18+
exit 2
1719
else
1820
query_string="$1"
1921
system_log="$2"
2022
fi
2123

2224
# obtain the unique list of hours where there's a match in the log
23-
grep "$query_string" $system_log | awk '{print $3, $4}' | cut -d: -f1 | sort -u | while read hour
25+
grep "$query_string" $system_log | sed -e 's/.* \([0-9]*-[0-9]*-[0-9]* [0-9]*\):.*/\1/' | sort -u | while read hour
2426
do
2527
# count number of occurences of query_string for given hour
2628
count=`grep "$query_string" $system_log | grep -c "$hour:"`

0 commit comments

Comments
 (0)
Please sign in to comment.