summaryrefslogtreecommitdiffstats
path: root/roles/awstats/files/combineHttpLogs.sh
blob: b997de9456c87aab379bef72470c3d87d65c3a04 (plain)
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
#!/bin/bash

# This file is part of Fedora Project Infrastructure Ansible
# Repository.
#
# Fedora Project Infrastructure Ansible Repository is free software:
# you can redistribute it and/or modify it under the terms of the GNU
# General Public License as published by the Free Software Foundation,
# either version 3 of the License, or (at your option) any later
# version.
#
# Fedora Project Infrastructure Ansible Repository is distributed in
# the hope that it will be useful, but WITHOUT ANY WARRANTY; without
# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
# PARTICULAR PURPOSE.  See the GNU General Public License for more
# details.
#
# You should have received a copy of the GNU General Public License
# along with Fedora Project Infrastructure Ansible Repository.  If
# not, see <http://www.gnu.org/licenses/>.

# Because sync-http may not get all logs for 3 days, we only merge
# things after 4 days. 

NUMDAYS=4
YEAR=$(/bin/date -d "-${NUMDAYS} days" +%Y)
MONTH=$(/bin/date -d "-${NUMDAYS} days" +%m)
DAY=$(/bin/date -d "-${NUMDAYS} days" +%d)

LOGDIR=/var/log/hosts
NFSDIR=/mnt/fedora_stats/combined-http
PROXYLOG=${LOGDIR}/proxy*/${YEAR}/${MONTH}/${DAY}/http/
DL_LOG=${LOGDIR}/download*/${YEAR}/${MONTH}/${DAY}/http/

TARGET=${NFSDIR}/${YEAR}/${MONTH}/${DAY}

LOGMERGE=/usr/share/awstats/tools/logresolvemerge.pl

FILES=$( ls -1 ${PROXYLOG}/*access.log.xz | awk '{x=split($0,a,"/"); print a[x]}' | sort -u )

mkdir -p ${TARGET}

for FILE in ${FILES}; do
    TEMP=$(echo ${FILE} | sed 's/\.xz$//')
    perl ${LOGMERGE} ${PROXYLOG}/${FILE} > ${TARGET}/${TEMP}
done

FILES=$( ls -1 ${DL_LOG}/dl*access.log.xz | awk '{x=split($0,a,"/"); print a[x]}' | sort -u )

mkdir -p ${TARGET}

for FILE in ${FILES}; do
    TEMP=$(echo ${FILE} | sed 's/\.xz$//')
    perl ${LOGMERGE} ${DL_LOG}/${FILE} > ${TARGET}/${TEMP}
done

# Now we link up the files into latest directory
# 1. make sure the latest directory exists
# 2. go into it.
# 3. remove the old links
# 4. link up all the files we merged over

if [[ -d ${NFSDIR}/latest ]]; then
    pushd ${NFSDIR}/latest &> /dev/null
    /bin/rm -f *
    for file in ../${YEAR}/${MONTH}/${DAY}/*; do
	ln -s ${file} .
    done
    popd &> /dev/null
fi