~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to utilities/page-performance-report-daily.sh

  • Committer: Francis J. Lacoste
  • Date: 2011-04-27 21:40:03 UTC
  • mto: This revision was merged to the branch mainline in revision 12971.
  • Revision ID: francis.lacoste@canonical.com-20110427214003-iiqhcyyswppyqjsx
Change the default timeout to production value, improved options documentation and use only one bin above timeout value.

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
 
3
3
#TZ=UTC # trace logs are still BST - blech
4
4
 
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
 
5
category_report() {
 
6
    max_log_age=$1
 
7
    type=$2
 
8
    from=$3
 
9
    until=$4
 
10
    category=$5
 
11
    log_root=$6
 
12
 
 
13
    local logs
 
14
    logs=`find ${log_root} \
 
15
        -maxdepth 2 -type f -mtime -${max_log_age} -name launchpad-trace\* \
 
16
        | sort | xargs -x`
 
17
 
 
18
    local root
 
19
    root=${HOME}/public_html/ppr/${category}
63
20
 
64
21
    local dir
65
 
    dir=${OUTPUT_ROOT}/`date -d $from +%Y-%m`/${type}_${from}_${until}
 
22
    dir=${root}/${type}_${from}_${until}
 
23
 
66
24
    mkdir -p ${dir}
67
25
 
68
26
    echo Generating report from $from until $until into $dir `date`
69
27
 
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
75
 
        ln -sf ${dir}/partition.html \
76
 
            ${OUTPUT_ROOT}/latest-${type}-partition.html
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
 
 
 
28
    ./page-performance-report.py -v --from=$from --until=$until \
 
29
        --top-urls=200 --directory=${dir} $logs
 
30
 
 
31
    ln -sf ${dir}/categories.html ${root}/latest-${type}-categories.html
 
32
    ln -sf ${dir}/pageids.html    ${root}/latest-${type}-pageids.html
 
33
    ln -sf ${dir}/combined.html   ${root}/latest-${type}-combined.html
 
34
    ln -sf ${dir}/top200.html   ${root}/latest-${type}-top200.html
 
35
    ln -sf ${dir}/timeout-candidates.html   \
 
36
        ${root}/latest-${type}-timeout-candidates.html
 
37
 
 
38
    return 0
 
39
    }
 
40
 
 
41
report() {
 
42
    category_report $* lpnet /srv/launchpad.net-logs/production
89
43
    return 0
90
44
}
91
45
 
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
 
46
fmt='+%Y-%m-%d'
 
47
 
 
48
now=`date $fmt`
 
49
 
 
50
report  3 daily `date -d yesterday $fmt` $now
 
51
 
 
52
if [ `date +%a` = 'Sat' ]; then
 
53
    report 9 weekly `date -d 'last week' $fmt` $now
 
54
fi
 
55
 
 
56
# We don't seem to have a months worth of tracelogs, but we will
 
57
# generate what we can.
 
58
if [ `date +%d` = '01' ]; then
 
59
    report 32 monthly `date -d 'last month' $fmt` $now
 
60
fi
 
61
 
 
62