diff --git a/COPYING b/COPYING index a3f3976c12d4b1e4db40e3d4108040029c28941e..28bf0933d5142942cb70fba5df579dbd3fae6b29 100644 --- a/COPYING +++ b/COPYING @@ -1,4 +1,4 @@ -Copyright (c) 2009, 2010, 2011 Andreas Olsson +Copyright (c) 2009-2012 Andreas Olsson Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation diff --git a/README b/README index 62f9899af7346c2008ddf7e45c8ced2b69df715f..8141bab0fe4fdded0329328ecb69b9e6ad96eefe 100644 --- a/README +++ b/README @@ -10,3 +10,9 @@ Nagios plugin which works by reading a text file containing a Unix timestamp of the most recent tarsnap backup. See the top comment in check_tarsnap for an example on how your tarsnap backup script can generate such a file. + +* tarsnap_usage +This Munin plugin keeps track on how much data a machine has backed up +on tarsnap. This is done by reading the current amount of data from a +text file, preferably updated by the tarsnap backup script. See the +plugin documentation for details. diff --git a/tarsnap_usage b/tarsnap_usage new file mode 100755 index 0000000000000000000000000000000000000000..f1940eecaa25ec2f6856215e6eb894e567739a45 --- /dev/null +++ b/tarsnap_usage @@ -0,0 +1,74 @@ +#!/bin/sh +# -*- sh -*- + +: << '=cut' + +=head1 NAME + +tarsnap_usage - Plugin to measure amount of tarsnap stored data + +=head1 CONFIGURATION + +By default the amount of data will be read from the file +/var/lib/tarsnap/status/data. Another file can be specified by setting +the variable datafile. + + [tarsnap_usage] + env.datafile /path/to/datafile + +=head2 DATA FILE + +The plugin expects the data file to contain a numeric value, and +nothing more, representing the number of bytes stored. One way to have +that file generated is by running something like the following at the +end of your tarsnap backup script. + + data=$(tarsnap --print-stats | sed -nre "s/^\s+\(unique data\)\s+[0-9]+\s+([0-9]+)$/\1/p") + [ -n "$data ] && echo "$data" > /var/lib/tarsnap/status/data + +=head1 AUTHOR + +Andreas Olsson <andreas@arrakis.se> + +=head1 LICENSE + +MIT License + +=head1 MAGIC MARKERS + + #%# family=auto + #%# capabilities=autoconf + +=cut + +if [ -z "$datafile" ]; then + datafile="/var/lib/tarsnap/status/data" +fi + +amount=$(cat "$datafile" 2> /dev/null) + +is_numeric () { + echo "$amount" | grep -Eq "^[0-9]+$" && return 0 || return 1 +} + +if [ "$1" = "autoconf" ]; then + is_numeric && echo yes || echo no + exit 0 +fi + +if [ "$1" = "config" ]; then + echo 'graph_title Tarsnap usage' + echo 'graph_vlabel byte stored' + echo 'data.label total usage' + echo 'graph_args --base 1000 -l 0' + echo 'graph_category disk' + echo 'graph_info Total amount of unique data backed up by tarsnap. That is, after deduplication and compression.' + exit 0 +fi + +if ! is_numeric; then + echo "Failed to read expected data from ${datafile}" + exit 1 +fi + +echo "data.value ${amount}"