/
report
executable file
·73 lines (59 loc) · 1.96 KB
/
report
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/bin/bash
if [ -z "$1" ]
then
echo "Usage: $0 date"
exit 1
fi
mkdir -p log_files
filename="log_files/$1.tsv"
if [ ! -f "$filename" ]
then
echo "Downloading log file..."
./client $1
echo "Log file downloaded."
fi
echo "Generating report."
cat $filename | grep $APP_NAME | awk '
$7 ~ /Syslog/ { SYSLOG++ }
$7 ~ /Local3/ && $10 ~ /at=info/ { LOCAL_3_OK++ }
$7 ~ /Local3/ && $10 ~ /at=error/ { LOCAL_3_ERR++ }
$7 ~ /Local7/ { LOCAL_7++ }
# OMG, awk has functions!
function print_report(headline, data)
{
total=0
# Calculate total requests for data set
for(key in data) { total+=data[key] }
printf("\n%s\n", headline)
i = 0; for(key in data) {
percentage = data[key] / total * 100
printf("(%.2f%) %d: %s\n", percentage, data[key], key)
i++; if(i == 10) { break }
}
}
match($0, /path="([^\?"]+)/, path_raw) { _path = path_raw[1] }
match($0, /method=HEAD.*path="\/"/) { HEAD_ROOT++; next }
match($0, /status=([0-9]+)/, status) { STATUS[status[1]]++ }
match($0, /status=500/) { STATUS_500[_path]++ }
match(_path, /\/(assets\/|favicon\.)/) { ASSET_REQ[_path]++ }
match($0, /host=([^ ]+)/, host) { HOSTNAME[host[1]]++ }
{
# I have no idea how to use negative lookahead regexp with match function
if(_path !~ /\/(assets\/|favicon\.)/) { REQ[_path]++ }
# $6 -> IP address
IP_REQ[$6]++
}
END {
# Sort associative arrays by values descending
PROCINFO["sorted_in"] = "@val_num_desc"
print "App requests (success/errors): " LOCAL_3_OK "/" LOCAL_3_ERR
print "Syslog: " SYSLOG
print "Other: " LOCAL_7
print "HEAD \"/\" requests: " HEAD_ROOT
print_report("# of requests per status code:", STATUS)
print_report("URLs with most 500s:", STATUS_500)
print_report("Top requested urls (except assets):", REQ)
print_report("Top requested assets:", ASSET_REQ)
print_report("Top IPs", IP_REQ)
print_report("Top hostname", HOSTNAME)
}'