Please note that if you have a ~/.mailFredStatus file, you need to delete the DIAGNOSTICS= line in order to use the new default. --writedefaults will put the new defaults into the file.
changelog: Added more diagnostics. Print the time of accumulation in human-readable form. Needed temp files to do this: create /tmp/mailFredStatusTEMPXXXXXX/ using mktemp -d each time mail is sent, being very careful to delete it after use. Man page had --append-diag while the actual working code had --add-diag. Default interval is now 2 hours. Print 24 hours of diagnostics the first time through, 6 hours subsequently. Current default list of diagnostics: requestSuccessRatio routingSuccessRatio localQueryTraffic outputBytes outputBytesTrailingAttempted searchFailedCount diffSearchSuccessTime diffTransferRate absDiffSearchSuccessTime absDiffTransferRate successTransferRate Note: if you have a ~/.mailFredStatus, these changes to defaults will not take effect. Either delete the file, or delete the lines which set values that are the default. 5075487247fb73c5b754937d3a0287ef mailFredStatus 7a9f8045b610f21bf56c92004c51d31b mailFredStatus.asc -- Ed Huff
#!/bin/bash
# if you edit your copy of this script, change the version.
VERSION='$Id: mailFredStatus,v 1.5 2003/11/07 07:49:52 ejhuff Exp $'
printMailHeaders() {
echo "To: $TO"
echo "From: $FROM"
echo "Errors-To: $FROM"
echo "Bcc: $BCC"
echo "Subject: Success probabilities $(date --utc)"
echo
}
DIAGNOSTIC_LINES=24 # first time through, print diagnostic data from last 24 hours.
printAssortedData() {
echo $VERSION
echo SERVLET=$SERVLET
TD=$(umask 077; mktemp -d /tmp/mailFredStatusTEMPXXXXXX) || exit 1
[ -z "$TD" ] && exit 1
[ "/tmp/mailFredStatusTEMP${TD:(-6)}" != "$TD" ] && exit 1
trap "echo trap EXIT; rm -f $TD/*; rmdir $TD" EXIT
date --utc "+Starting: %Y-%m-%d %H:%M:%S UTC"
wget -O - "http://$SERVLET/servlet/nodeinfo/performance/general" 2>/dev/null \
| tr -d "\n" \
| sed 's/<tr>/@<tr>/g' \
| sed 's|</tr>|</tr>@|' \
| sed 's/<[^>]*>/ /g; s/ * @/@/g; s/@ */@/g; s/ */ /g' \
| sed 's/Uptime[@ ]* /Uptime /g' \
| tr '@' "\n" \
| egrep 'Version|Build|Uptime|Current|Active' \
| grep -v 'README'
wget -O - "http://$SERVLET/servlet/nodeinfo/networking/ocm?setLevel=1&setMode=new" 2>/dev/null \
| egrep '^<tr><td>[^<]' \
| sed 's/<[^>]*>/ /g; s/^ *//g; s/ */ /g; s/ / /g'
echo
echo "Network Load:"
wget -O - "http://$SERVLET/servlet/nodeinfo/networking/loadstats" 2>/dev/null \
| sed 's/<[^>]*>/ /g; s/^ *//g; s/ */ /g; s/ / /g' \
| grep '^[A-Za-z() ]*:'
echo
echo "Frost, etc. status:"
echo "$FROST_ETC_STATUS"
echo
echo "Traffic shaping:"
echo $TC '-s qdisc show dev eth0 | head -3'
$TC -s qdisc show dev eth0 | head -3
echo Non-default non-bookmark freenet.conf lines
grep '^[a-zA-Z]' freenet.conf | grep -v bookmark
echo
echo Parameters to last startup:
ls -l --full-time freenet.last-startup
cat freenet.last-startup
echo
echo "$NETSTAT -n --inet | egrep -v :6000\|:8888\|\^tcp\ \*0\ \*0\ | grep ESTAB | sort -k 2nr,2 -k 3nr,3"
$NETSTAT -n --inet | head -2
$NETSTAT -n --inet | egrep -v :6000\|:8888\|\^tcp\ \*0\ \*0\ | grep ESTAB | sort -k 2nr,2 -k 3nr,3
echo
wget -O - http://$SERVLET/servlet/nodestatus/psuccess_data.txt 2>/dev/null
echo
wget -O - http://$SERVLET/servlet/nodeinfo/internal/env 2>/dev/null \
| grep '^<tr><td>' \
| sed 's/<[^>]*>/ /g; s/^ *//g; s/ */ /g' \
| egrep 'Architecture|processors|Operating|Version|JVM|Maximum|Percent|Total'
echo
wget -O - http://$SERVLET/servlet/nodestatus/nodestatus.html 2>/dev/null \
| grep '^<tr><td>' \
| grep -v '<b>' \
| sed 's/<[^>]*>/ /g; s/^ *//g; s/ */ /g'
echo
for diag in $DIAGNOSTICS ; do
echo
echo "$diag"
wget -O $TD/$diag \
http://$SERVLET/servlet/nodestatus/diagnostics/$diag/raw \
2>/dev/null
grep '#' $TD/$diag
grep hour $TD/$diag | tail -$DIAGNOSTIC_LINES \
| cut -s --fields=3- > $TD/c3on
for secs in $(grep hour $TD/$diag | tail -$DIAGNOSTIC_LINES \
| cut -s --fields=2 | grep '^[0-9][0-9]*$'); do
date --utc --date="19700101 utc $secs seconds" "+%Y-%m-%d %H:%M:%S UTC"
done | paste - $TD/c3on
rm $TD/$diag $TD/c3on
done
date --utc "+Finished: %Y-%m-%d %H:%M:%S UTC"
rm -f $TD/*; rmdir $TD
trap - EXIT
DIAGNOSTIC_LINES=6
}
[ -z "$TO" ] && TO="Toad <[EMAIL PROTECTED]>"
[ -z "$FROM" ] && FROM="[EMAIL PROTECTED]:-localhost}"
[ -z "$BCC" ] && BCC="[EMAIL PROTECTED]:-localhost}"
[ -z "$INTERVAL" ] && INTERVAL=7200
[ -z "$SERVLET" ] && SERVLET=127.0.0.1:8888
[ -z "$FREENETHOME" ] && FREENETHOME=$HOME/freenet/
[ -z "$VERBOSE" ] && VERBOSE=
[ -z "$GOLIVE" ] && GOLIVE=
[ -z "$SENDMAIL" ] && SENDMAIL=/usr/sbin/sendmail
[ -z "$TC" ] && TC=/sbin/tc
[ -z "$NETSTAT" ] && NETSTAT=/bin/netstat
[ -z "$FROST_ETC_STATUS" ] && FROST_ETC_STATUS="Frost, etc. status unknown."
[ -z "$DIAGNOSTICS" ] && DIAGNOSTICS="requestSuccessRatio routingSuccessRatio localQueryTraffic outputBytes outputBytesTrailingAttempted searchFailedCount diffSearchSuccessTime diffTransferRate absDiffSearchSuccessTime absDiffTransferRate successTransferRate"
HELP=
WRITEDEFAULTS=
if [ -f ~/.mailFredStatus ] ; then
source ~/.mailFredStatus
fi
while [[ $# > 0 ]] ; do
case "$1" in
--to)
TO=$2
shift;;
--from)
FROM=$2
shift;;
--BCC)
BCC=$2
shift;;
--interval)
INTERVAL=$2
shift;;
--servlet)
SERVLET=$2
shift;;
--FreenetHOME|--freenetHOME|--FreeNetHOME|--freenethome)
FREENETHOME=$2
shift;;
--verbose)
VERBOSE=-v
;;
--sendmail)
SENDMAIL=$2
shift;;
--tc)
TC=$2
shift;;
--netstat)
NETSTAT=$2
shift;;
--frost*)
FROST_ETC_STATUS="$2"
shift;;
--add-diag*)
DIAGNOSTICS="$DIAGNOSTICS $2"
shift;;
--set-diag*)
DIAGNOSTICS="$2"
shift;;
--dryrun)
GOLIVE=
;;
--golive)
GOLIVE=TRUE
;;
--v*|--V*|-v|-V)
echo $VERSION
echo mailFredStatus --help for help.
exit 0
;;
--write*|-w*)
WRITEDEFAULTS=TRUE
;;
--h*|-h*)
HELP=TRUE
;;
*)
HELP=TRUE
echo "$1 interpreted as --help"
;;
esac
shift
done
if [ ! -z "$WRITEDEFAULTS" ] ; then
echo "Making current options the defaults in ~/.mailFredStatus"
(cat <<EOF
TO="$TO"
FROM="$FROM"
BCC="$BCC"
INTERVAL="$INTERVAL"
SERVLET="$SERVLET"
FREENETHOME="$FREENETHOME"
VERBOSE="$VERBOSE"
SENDMAIL="$SENDMAIL"
TC="$TC"
NETSTAT="$NETSTAT"
FROST_ETC_STATUS="$FROST_ETC_STATUS"
DIAGNOSTICS="$DIAGNOSTICS"
GOLIVE="$GOLIVE"
EOF
) > ~/.mailFredStatus
echo New contents of ~/.mailFredStatus:
cat ~/.mailFredStatus
echo
echo Done.
exit 0
fi
if [ ! -z "$HELP" ] ; then
# will do $VAR substitution in the text.
cat <<EOF
NAME
mailFredStatus - Mail Freenet REference Daemon status to Toad
SYNOPSIS
mailFredStatus [ --help | -h | --version | -v ]
mailFredStatus [ --to '$TO' ]
[ --from '$FROM' ]
[ --BCC '$BCC' ]
[ --interval '$INTERVAL' ]
[ --servlet '$SERVLET' ]
[ --FreenetHOME '$FREENETHOME' ]
[ --dryrun | --golive ]
[ --sendmail '$SENDMAIL' ]
[ --tc '$TC' ]
[ --netstat '$NETSTAT' ]
[ --frost '$FROST_ETC_STATUS' ]
[ --add-diag 'additional_diagnostic_name(s)' ]
[ --set-diag '$DIAGNOSTICS' ]
[ --verbose ]
[ --writedefaults ]
DESCRIPTION
mailFredStatus will collect status information from
the Fred FProxy server at localhost:8888, from freenet.conf,
and from netstat, and mail it to Toad once an hour.
The command never exits unless interrupted or killed.
Uses sleep to delay, so intervals are approximate.
The --golive option must be specified to actually
send any mail. To make --golive the default, use
this command, with desired defaults specified.
mailFredStatus [defaults] --golive --writedefaults
This will not actually go live, but the next time
mailFredStatus is invoked, it will start running.
--verbose will cause the -v option to be passed
to $SENDMAIL.
--frost "Frost, etc. status (running or not)" will
include the string in the email stating your normal
configuration. If you sometimes run Frost and sometimes
don't, either say "maybe maybe not" or fix the script
to find out.
--add-diag will add a diagnostic to the list of
diagnostic statistics for which the last 4 hours
of hourly accumulations are included. These are at
http://IP:PORT/servlet/nodestatus/diagnostics/theDiagName/raw
--set-diag will set a new list of diagnostic names.
FILES
~/.mailFredStatus
If ~/.mailFredStatus exists then this script
sources it. It should assign default values to
the environment variables. The --writedefaults
will overwrite any existing ~/.mailFredStatus
specifying the options from the command line as
the new defaults. Remove the file to use the
original defaults.
ENVIRONMENT
PATH must include wget head egrep grep sort sed date
If exported to the environment, these environment variables
will be used as the defaults for the corresponding options.
Or, if defined in ~/.mailFredStatus, then those values
will override environment or script defaults.
They do not override command line options.
Shown are the values which were in effect after
processing the command line which caused this printout.
TO="$TO"
FROM="$FROM"
BCC="$BCC"
INTERVAL="$INTERVAL"
SERVLET="$SERVLET"
FREENETHOME="$FREENETHOME"
VERBOSE="$VERBOSE"
SENDMAIL="$SENDMAIL"
TC="$TC"
NETSTAT="$NETSTAT"
FROST_ETC_STATUS="$FROST_ETC_STATUS"
DIAGNOSTICS="$DIAGNOSTICS"
GOLIVE="$GOLIVE"
AUTHOR
Edward J. Huff <[EMAIL PROTECTED]> ejhuff on sourceforge.
Report problems on the Freenet devloment list:
Discussion of development issues <[EMAIL PROTECTED]>
FEATURES
Only works on Linux. Uses bash-isms.
Uses wget to read data from servlet. IP and port are configurable.
BUGS
Extracts data from web pages, so that innocent changes
to fproxy formatting may break this script.
Isn't written in [ perl | java | /bin/sh | ... ]
Uses sendmail to send mail.
VERSION
$VERSION
EOF
exit 0
fi
echo Changing directory to $FREENETHOME
cd $FREENETHOME
if [[ -z "$GOLIVE" ]] ; then
echo This is a dry run.
echo To go live, you must specify --golive.
echo To make --golive the default, specify --golive --writedefaults.
echo
echo Mail headers would be:
printMailHeaders
echo
echo The mail body would be:
printAssortedData
echo
echo Note that the first mail includes 24 hours of diagnostic values,
echo while subsequent mails include only 6.
exit 0
fi
echo
echo Mail headers will be:
printMailHeaders
echo
echo "Type ^C to abort. First mail goes out in about $INTERVAL seconds."
echo -n "That will be about "
date --date "today $INTERVAL seconds"
while true; do
sleep $INTERVAL
(
printMailHeaders
printAssortedData 2>&1
echo '.'
) | $SENDMAIL $VERBOSE -t -f "$FROM"
done
-----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.1 (GNU/Linux) iD8DBQA/q07kJfKDstX6FxkRAqB0AKCOIQtNQeD5a8IVJZv504zomC2CegCgm5Q1 ncmSOt6KF60H7QJYzZVqaLc= =TCYs -----END PGP SIGNATURE-----
signature.asc
Description: This is a digitally signed message part
_______________________________________________ Devl mailing list [EMAIL PROTECTED] http://dodo.freenetproject.org/cgi-bin/mailman/listinfo/devl
