Skip to content

Instantly share code, notes, and snippets.

@filipsPL
Created June 6, 2020 06:44
Show Gist options
  • Save filipsPL/d5cb27f879261f05c139badc5c0abf40 to your computer and use it in GitHub Desktop.
Save filipsPL/d5cb27f879261f05c139badc5c0abf40 to your computer and use it in GitHub Desktop.
rsync transfer data munin plugin - debian 10

rsync transfer data munin plugin - debian 10

For new installations the provided rsync_bytes plugin doesn't work. Here is rewrittend (and path-hardcoded) version which does work.

Please remember that the rsync logfile must be outside the /home directory, see here

Before use, install logtail.

#!/bin/bash
#
# Plugin to monitor rsyncd.
# based on previous work by jintxo
#
# Parameters understood:
#
# config (required)
# autoconf (optional)
#
#
# https://serverfault.com/questions/1004695/munin-node-plugins-on-debian-10-cannot-read-from-home-directories-debian-9-work
# munin-node package in Debian 10 includes /lib/systemd/system/munin-node.service, which sets ProtectHome=true. Debian 9's munin-node package does not have this file.
# Setting ProtectHome=read-only is one solution, or even ProtectHome=false to include write access. However the ProtectHome flag exists for good reasons. Arranging for the plugin to read its data
mktempfile () {
mktemp -t $1
}
# make sure these values are set correctly:
RSYNCD_LOG=/var/log/rsync.log
LOGTAIL=/usr/sbin/logtail
STATEFILE=/var/lib/munin-node/plugin-state/nobody/rsync-bytes.offset
if [ "$1" = "autoconf" ]; then
if [ -f "${RSYNCD_LOG}" -a -n "${LOGTAIL}" -a -x "${LOGTAIL}" ] ; then
echo yes
else
echo no
fi
exit 0
fi
if [ "$1" = "config" ]; then
echo 'graph_title Rsync Server Bytes'
echo 'graph_args --base 1000 -l 0'
echo 'graph_order send recv'
echo 'graph_category filetransfer'
echo 'graph_vlabel Rsync Bytes'
echo 'send.label Bytes Send'
echo 'recv.label Bytes Recv'
exit 0
fi
send=U
recv=U
TEMP_FILE=`mktempfile munin-rsync-bytes.XXXXXX`
if [ -n "$TEMP_FILE" -a -f "$TEMP_FILE" ]
then
$LOGTAIL ${RSYNCD_LOG} $STATEFILE | grep " total size " > ${TEMP_FILE}
# sent 51 bytes received 276927 bytes total size 20705477
send=`grep ' sent .* bytes' ${TEMP_FILE} | awk '{s += $5} END { if ( s ) print s ; else print "0" }'`
recv=`grep ' received .* bytes' ${TEMP_FILE} | awk '{s += $8} END { if ( s ) print s ; else print "0" }'`
/bin/rm -f $TEMP_FILE
fi
echo "send.value ${send}"
echo "recv.value ${recv}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment