10209.2.41
by Stuart Bishop
Regular schedule of page-performance-report.py |
1 |
#!/bin/sh
|
10209.2.45
by Stuart Bishop
Daily report run updates |
2 |
|
10209.2.41
by Stuart Bishop
Regular schedule of page-performance-report.py |
3 |
#TZ=UTC # trace logs are still BST - blech
|
4 |
||
12929.1.1
by Francis J. Lacoste
Support generating reports for specific day. Use --merge options for period longer than one day. |
5 |
CATEGORY=lpnet |
6 |
LOGS_ROOTS="/srv/launchpad.net-logs/production /srv/launchpad.net-logs/edge" |
|
7 |
OUTPUT_ROOT=${HOME}/public_html/ppr/lpnet |
|
8 |
DAY_FMT="+%Y-%m-%d" |
|
9 |
||
10 |
find_logs() { |
|
11 |
from=$1 |
|
12 |
until=$2 |
|
13 |
||
14 |
end_mtime_switch= |
|
15 |
days_to_end="$(expr `date +%j` - `date -d $until +%j` - 1)" |
|
16 |
if [ $days_to_end -gt 0 ]; then |
|
17 |
end_mtime_switch="-daystart -mtime +$days_to_end" |
|
18 |
fi
|
|
19 |
||
20 |
find ${LOGS_ROOTS} \ |
|
21 |
-maxdepth 2 -type f -newermt "$from - 1 day" $end_mtime_switch \ |
|
22 |
-name launchpad-trace\* \ |
|
23 |
| sort | xargs -x |
|
24 |
}
|
|
25 |
||
26 |
# Find all the daily stats.pck.bz2 $from $until
|
|
27 |
find_stats() { |
|
28 |
from=$1 |
|
29 |
until=$2 |
|
30 |
||
31 |
# Build a string of all the days within range.
|
|
32 |
local dates
|
|
33 |
local day
|
|
34 |
day=$from |
|
35 |
while [ $day != $until ]; do |
|
36 |
dates="$dates $day" |
|
37 |
day=`date $DAY_FMT -d "$day + 1 day"` |
|
38 |
done
|
|
39 |
||
40 |
# Use that to build a regex that will be used to select
|
|
41 |
# the files to use.
|
|
42 |
local regex
|
|
43 |
regex="daily_(`echo $dates |sed -e 's/ /|/g'`)" |
|
44 |
||
45 |
find ${OUTPUT_ROOT} -name 'stats.pck.bz2' | egrep $regex |
|
46 |
}
|
|
47 |
||
48 |
report() { |
|
49 |
type=$1 |
|
50 |
from=$2 |
|
51 |
until=$3 |
|
52 |
link=$4 |
|
53 |
||
54 |
local files
|
|
55 |
local options
|
|
56 |
if [ "$type" = "daily" ]; then |
|
57 |
files=`find_logs $from $until` |
|
58 |
options="--from=$from --until=$until" |
|
59 |
else
|
|
60 |
files=`find_stats $from $until` |
|
61 |
options="--merge" |
|
62 |
fi
|
|
10209.2.41
by Stuart Bishop
Regular schedule of page-performance-report.py |
63 |
|
64 |
local dir
|
|
12929.1.1
by Francis J. Lacoste
Support generating reports for specific day. Use --merge options for period longer than one day. |
65 |
dir=${OUTPUT_ROOT}/`date -d $from +%Y-%m`/${type}_${from}_${until} |
10209.2.45
by Stuart Bishop
Daily report run updates |
66 |
mkdir -p ${dir} |
67 |
||
68 |
echo Generating report from $from until $until into $dir `date` |
|
69 |
||
12929.1.1
by Francis J. Lacoste
Support generating reports for specific day. Use --merge options for period longer than one day. |
70 |
./page-performance-report.py -v --top-urls=200 --directory=${dir} \ |
71 |
$options $files |
|
72 |
||
73 |
# Only do the linking if requested.
|
|
74 |
if [ "$link" = "link" ]; then |
|
12929.6.15
by Francis J. Lacoste
Link latest partition.html in top-level directory. |
75 |
ln -sf ${dir}/partition.html \ |
76 |
${OUTPUT_ROOT}/latest-${type}-partition.html |
|
12929.1.1
by Francis J. Lacoste
Support generating reports for specific day. Use --merge options for period longer than one day. |
77 |
ln -sf ${dir}/categories.html \ |
78 |
${OUTPUT_ROOT}/latest-${type}-categories.html |
|
79 |
ln -sf ${dir}/pageids.html \ |
|
80 |
${OUTPUT_ROOT}/latest-${type}-pageids.html |
|
81 |
ln -sf ${dir}/combined.html \ |
|
82 |
${OUTPUT_ROOT}/latest-${type}-combined.html |
|
83 |
ln -sf ${dir}/metrics.dat ${OUTPUT_ROOT}/latest-${type}-metrics.dat |
|
84 |
ln -sf ${dir}/top200.html ${OUTPUT_ROOT}/latest-${type}-top200.html |
|
85 |
ln -sf ${dir}/timeout-candidates.html \ |
|
86 |
${OUTPUT_ROOT}/latest-${type}-timeout-candidates.html |
|
87 |
fi
|
|
88 |
||
10209.2.45
by Stuart Bishop
Daily report run updates |
89 |
return 0 |
90 |
}
|
|
91 |
||
12929.1.1
by Francis J. Lacoste
Support generating reports for specific day. Use --merge options for period longer than one day. |
92 |
local link
|
93 |
if [ "$3" = "-l" ]; then |
|
94 |
link="link" |
|
95 |
fi
|
|
96 |
||
97 |
if [ "$1" = '-d' ]; then |
|
98 |
report daily `date -d $2 $DAY_FMT` `date -d "$2 + 1 day" $DAY_FMT` $link |
|
99 |
elif [ "$1" = '-w' ]; then |
|
100 |
report weekly `date -d $2 $DAY_FMT` `date -d "$2 + 1 week" $DAY_FMT` $link |
|
101 |
elif [ "$1" = '-m' ]; then |
|
102 |
report monthly `date -d $2 $DAY_FMT` `date -d "$2 + 1 month" $DAY_FMT` $link |
|
103 |
else
|
|
104 |
# Default invocation used from cron to generate latest one.
|
|
105 |
now=`date $DAY_FMT` |
|
106 |
report daily `date -d yesterday $DAY_FMT` $now link |
|
107 |
||
108 |
if [ `date +%a` = 'Sun' ]; then |
|
109 |
report weekly `date -d 'last week' $DAY_FMT` $now link |
|
110 |
fi
|
|
111 |
||
112 |
if [ `date +%d` = '01' ]; then |
|
113 |
report monthly `date -d 'last month' $DAY_FMT` $now link |
|
114 |
fi
|
|
115 |
fi
|