# Copyright (c) 2010-2013 Index Data, http://www.indexdata.com

all: help

SCRIPTS=	ppstat pp-days
CFREPO_WWW_DIR=		/var/www/cfrepo
CFREPO_DATA_DIR=	/var/lib/cf-repo/.statistic
MUNIN_PLUGIN_DIR=	 /usr/share/munin/plugins

MP_STAT_FILES=	.pazpar2-today.csv \
		.pazpar2-week.csv \


# test & development
LOGFILE=	../share/pazpar2-2013-01-24.log.gz

PERL=	perl
PPSTAT=	${PERL} ./ppstat
ZCAT=	gzip -dcf

test: validate
validate:
	${ZCAT} ${LOGFILE} | egrep -v -f ../share/debug.txt | egrep -v -f ../share/error.txt

today:
	./error-today
today-total:
	./error-today | perl -npe 's,.{23}\[.*?\] ,,' | sort | uniq -c | sort -nr

yesterday:
	./error-yesterday
yesterday-total:
	./error-yesterday | perl -npe 's,.{23}\[.*?\] ,,' | sort | uniq -c | sort -nr

week:
	./error-week
week-total:
	./error-week | perl -npe 's,.{23}\[.*?\] ,,' | sort | uniq -c | sort -nr

month:
	./error-all
month-total:
	./error-all | perl -npe 's,.{23}\[.*?\] ,,' | sort | uniq -c | sort -nr

install: install-cfrepo-statistic-symlinks

install-munin install-munin-plugin:
	sudo cp ../munin/pazpar2-memory ${MUNIN_PLUGIN_DIR}/
	sudo cp ../munin/pazpar2-crash ${MUNIN_PLUGIN_DIR}/
	cd /etc/munin/plugins && sudo ln -fs ${MUNIN_PLUGIN_DIR}/pazpar2* .
	sudo /etc/init.d/munin-node restart

install-cfrepo-statistic-symlinks:
	sudo mkdir -p ${CFREPO_DATA_DIR}

perltidy:
	perltidy -b ${SCRIPTS}

clean distclean:
	rm -f *.bak *.tdy

help:
	@echo "make [ all | clean | test ]"
	@echo "     [ today | yesterday | week | month ]"
	@echo "     [ today-total | yesterday-total | week-total | month-total ]"
	@echo "     [ install-munin-plugin ]"
	@echo "     [ install-cfrepo-statistic-symlinks ]"

