From: Chris Sharp Date: Wed, 27 Jan 2016 16:18:37 +0000 (-0500) Subject: adding log-analyzer scripts for postgres X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=9e3bbd82f514bbb6c1e705c5a632360d0b33512a;p=contrib%2Fpines.git adding log-analyzer scripts for postgres --- diff --git a/logger/pg-log-analyzer b/logger/pg-log-analyzer new file mode 100755 index 0000000..f41539d --- /dev/null +++ b/logger/pg-log-analyzer @@ -0,0 +1,71 @@ +#!/bin/bash + +# This program runs pgfouine or pgbadger to process postresql logs +# and outputs the reports into a pre-defined directory. +# It will check to previous our from the time the program +# is executed in order to get all transactions for the hour. + + +########### Config Section ########### + +## The directory that the logs are stored in. +LOGDIR="/var/log/evergreen" + +## The output directory. +OUTDIR="/var/www/pg_reports" + +## The output filename. +OUTFILE="$(date +%F)-pg" + +## The logfile for this script +ANALYZER_LOG="/var/log/pg-log-analyzer.log" +###################################### + + +## The date/time this script is run. +RUN_DATE="$(date)" + +## The absolute path to the current day's logs file +LOGPATH="$LOGDIR/$(date +%Y/%m/%d)" + +## The hour of time the program is run +CURRENT_HOUR="$(date +%H)" + +## This subracts one hour from the current hour +HOUR="$(( $(date +%k) - 1 ))" +## Then we pad the $HOUR with a '0' +HOUR="$(printf "%02d\n" $HOUR)" + +## The current day's log files +LOGDAY="$(date +%Y/%m/%d)" + + +## Since we check 1 hour behind +## we make sure to set the day yesterday +## when our current runtime is 12:00 AM +if [ "$CURRENT_HOUR" = "00" ] +then + HOUR="23" + LOGDAY="$(date -d '1 day ago' +%Y/%m/%d)" + OUTFILE="$(date -d '1 day ago' +%F)-pg" +fi + + + +## This does the actual work. +case $1 in +pgfouine) + echo -n "$RUN_DATE " >> "$ANALYZER_LOG" + pgfouine -file $LOGDIR/$LOGDAY/pg.$HOUR.log -logtype stderr > $OUTDIR/$OUTFILE.$HOUR.log.html 2>> "$ANALYZER_LOG" +;; +pgbadger) + echo -n "$RUN_DATE " >> "$ANALYZER_LOG" + pgbadger --format syslog --outfile $OUTDIR/$OUTFILE.$HOUR.log.html $LOGDIR/$LOGDAY/pg.$HOUR.log 2>> "$ANALYZER_LOG" +;; +*) + echo + echo usage:- + echo "<$0 pgfouine> to use pgfouine -or-" + echo "<$0 pgbadger> to use pgbadger" + exit 1 +esac diff --git a/logger/pg-log-analyzer-cron b/logger/pg-log-analyzer-cron new file mode 100755 index 0000000..284e940 --- /dev/null +++ b/logger/pg-log-analyzer-cron @@ -0,0 +1,7 @@ +#!/bin/sh + +### This will allow pg-log-analyzer to be run from cron - aw + +PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin + +/root/eg/pg-log-analyzer pgbadger