Révision 21379f58
Add plugin "rsnapshot_duration"
The plugin monitors the duration of rsnapshot backups for each single
backup source.
The duration is parsed from rsnapshot's log file. The rsnapshot
configuration setting "loglevel 3" is required.
| plugins/rsnapshot/rsnapshot_duration | ||
|---|---|---|
| 1 |
#!/bin/sh |
|
| 2 |
|
|
| 3 |
: <<=cut |
|
| 4 |
|
|
| 5 |
=head1 NAME |
|
| 6 |
|
|
| 7 |
rsnapshot_duration - monitor duration of rsnapshot backups in detail |
|
| 8 |
|
|
| 9 |
|
|
| 10 |
=head1 APPLICABLE SYSTEMS |
|
| 11 |
|
|
| 12 |
Any system with local access to an rsnapshot log file. |
|
| 13 |
|
|
| 14 |
|
|
| 15 |
=head1 CONFIGURATION |
|
| 16 |
|
|
| 17 |
rsnapshot's configuration file (e.g. /etc/rsnapshot.conf) needs to |
|
| 18 |
contain the directive "loglevel 3" in order to write the required |
|
| 19 |
log messages to the log file. |
|
| 20 |
|
|
| 21 |
|
|
| 22 |
The following configuration represents the plugin's defaults: |
|
| 23 |
|
|
| 24 |
[rsnapshot_duration] |
|
| 25 |
env.rsnapshot_log_file /var/log/rsnapshot |
|
| 26 |
env.rsnapshot_operation_name beta |
|
| 27 |
env.rsnapshot_description Backup Duration |
|
| 28 |
|
|
| 29 |
"rsnapshot_description" is used for the title of the graph. |
|
| 30 |
|
|
| 31 |
"rsnapshot_operation_name" refers to the interval/retain/level of the |
|
| 32 |
rsnapshot operation to be monitored. This should be the lowest |
|
| 33 |
executed backup interval (e.g. "daily" or "beta"). In case of the |
|
| 34 |
rsnapshot setting "sync_first 1", it should be "sync". |
|
| 35 |
|
|
| 36 |
Multiple rsnapshot log files (with different sets of backup sources) |
|
| 37 |
can be monitored. Simply create one plugin symlink for each log file |
|
| 38 |
and specify suitable plugin configurations for each symlink name. |
|
| 39 |
|
|
| 40 |
|
|
| 41 |
=head1 INTERPRETATION |
|
| 42 |
|
|
| 43 |
The backup duration for each single "backup" task is calculated based |
|
| 44 |
on the difference of the timestamps in the log file. |
|
| 45 |
|
|
| 46 |
|
|
| 47 |
=head1 AUTHOR |
|
| 48 |
|
|
| 49 |
Lars Kruse <devel@sumpfralle.de> |
|
| 50 |
|
|
| 51 |
|
|
| 52 |
=head1 LICENSE |
|
| 53 |
|
|
| 54 |
SPDX-License-Identifier: GPL-3.0-or-later |
|
| 55 |
|
|
| 56 |
|
|
| 57 |
=head1 MAGIC MARKERS |
|
| 58 |
|
|
| 59 |
#%# family=auto |
|
| 60 |
#%# capabilities=autoconf |
|
| 61 |
|
|
| 62 |
|
|
| 63 |
=cut |
|
| 64 |
|
|
| 65 |
|
|
| 66 |
set -eu |
|
| 67 |
|
|
| 68 |
|
|
| 69 |
. "$MUNIN_LIBDIR/plugins/plugin.sh" |
|
| 70 |
|
|
| 71 |
|
|
| 72 |
LOG_FILE=${rsnapshot_log_file:-/var/log/rsnapshot.log}
|
|
| 73 |
RSNAPSHOT_OPERATION_NAME=${rsnapshot_operation_name:-beta}
|
|
| 74 |
RSNAPSHOT_DESCRIPTION=${rsnapshot_description:-Backup Duration}
|
|
| 75 |
|
|
| 76 |
|
|
| 77 |
# retrieve the latest set of log files for a complete backup operation |
|
| 78 |
get_latest_process_log() {
|
|
| 79 |
tac "$LOG_FILE" \ |
|
| 80 |
| awk ' |
|
| 81 |
BEGIN { in_process = 0; }
|
|
| 82 |
/ '"$RSNAPSHOT_OPERATION_NAME"': completed[, ]/ { in_process = 1; }
|
|
| 83 |
/ '"$RSNAPSHOT_OPERATION_NAME"': started$/ { if (in_process == 1) exit; }
|
|
| 84 |
{ if (in_process == 1) print($0); }' \
|
|
| 85 |
| tac |
|
| 86 |
} |
|
| 87 |
|
|
| 88 |
|
|
| 89 |
# parse rsnapshot log lines |
|
| 90 |
# output format: |
|
| 91 |
# BACKUP_NAME DURATION_SECONDS [ERROR_MESSAGES] |
|
| 92 |
get_backups_with_duration() {
|
|
| 93 |
get_latest_process_log | while read -r timestamp command details; do |
|
| 94 |
parsed_timestamp=$(date +%s --date "$(printf '%s' "$timestamp" | tr -d '[]')") |
|
| 95 |
if [ -n "${backup_name:-}" ] && printf '%s' "$command" | grep -q "/rsnapshot$" && printf '%s' "$details" | grep -q "ERROR:"; then
|
|
| 96 |
backup_errors=$(printf '%s' "$details" | sed 's/^.*ERROR: //') |
|
| 97 |
elif printf '%s' "$command" | grep -q "/rsync$"; then |
|
| 98 |
if [ -n "${backup_name:-}" ]; then
|
|
| 99 |
printf '%s\t%d\t%s\n' "$backup_name" "$((parsed_timestamp - backup_start))" "${backup_errors:-}"
|
|
| 100 |
fi |
|
| 101 |
backup_name=$(printf '%s' "$details" | sed 's#/$##' | sed 's#^.*/##') |
|
| 102 |
backup_start=$parsed_timestamp |
|
| 103 |
backup_errors= |
|
| 104 |
elif printf '%s' "$command" | grep -q "/rm$"; then |
|
| 105 |
# the backup is finished |
|
| 106 |
if [ -n "${backup_name:-}" ]; then
|
|
| 107 |
printf '%s\t%d\t%s\n' "$backup_name" "$((parsed_timestamp - backup_start))" "${backup_errors:-}"
|
|
| 108 |
fi |
|
| 109 |
break |
|
| 110 |
fi |
|
| 111 |
done | sort |
|
| 112 |
} |
|
| 113 |
|
|
| 114 |
|
|
| 115 |
do_autoconf() {
|
|
| 116 |
if [ -e "$LOG_FILE" ]; then |
|
| 117 |
if [ -r "$LOG_FILE" ]; then |
|
| 118 |
if command -v "tac" >/dev/null; then |
|
| 119 |
echo "yes" |
|
| 120 |
else |
|
| 121 |
echo "no (executable 'tac' (coreutils) is missing)" |
|
| 122 |
fi |
|
| 123 |
else |
|
| 124 |
echo "no (rsnapshot log file is not readable: $LOG_FILE)" |
|
| 125 |
fi |
|
| 126 |
else |
|
| 127 |
echo "no (rsnapshot log file missing: $LOG_FILE)" |
|
| 128 |
fi |
|
| 129 |
exit 0 |
|
| 130 |
} |
|
| 131 |
|
|
| 132 |
|
|
| 133 |
get_backup_fieldname() {
|
|
| 134 |
local backup_name="$1" |
|
| 135 |
clean_fieldname "backup_${backup_name}"
|
|
| 136 |
} |
|
| 137 |
|
|
| 138 |
|
|
| 139 |
print_backup_details() {
|
|
| 140 |
local backup_name="$1" |
|
| 141 |
local backup_duration="$2" |
|
| 142 |
local backup_messages="$3" |
|
| 143 |
local fieldname |
|
| 144 |
fieldname=$(get_backup_fieldname "$backup_name") |
|
| 145 |
printf '%s.value %s\n' "$fieldname" "$backup_duration" |
|
| 146 |
if [ -n "$backup_messages" ]; then |
|
| 147 |
printf '%s.extinfo %s\n' "$fieldname" "$backup_messages" |
|
| 148 |
fi |
|
| 149 |
} |
|
| 150 |
|
|
| 151 |
|
|
| 152 |
do_config() {
|
|
| 153 |
local do_emit_values="${1:-0}"
|
|
| 154 |
echo "graph_title rsnapshot - $RSNAPSHOT_DESCRIPTION" |
|
| 155 |
echo 'graph_vlabel Duration of backup in minutes' |
|
| 156 |
echo 'graph_category backup' |
|
| 157 |
echo 'graph_scale no' |
|
| 158 |
get_backups_with_duration | while read -r name duration messages; do |
|
| 159 |
fieldname=$(clean_fieldname "backup_$name") |
|
| 160 |
printf '%s.label %s\n' "$fieldname" "$name" |
|
| 161 |
printf '%s.draw %s\n' "$fieldname" "AREASTACK" |
|
| 162 |
# The duration is stored as an SI unit (seconds). |
|
| 163 |
# The visualization as the number of minutes should be suitable for most backups. |
|
| 164 |
printf '%s.cdef %s,60,/\n' "$fieldname" "$fieldname" |
|
| 165 |
if [ "$do_emit_values" = "1" ]; then |
|
| 166 |
print_backup_details "$name" "$duration" "$messages" |
|
| 167 |
fi |
|
| 168 |
done |
|
| 169 |
} |
|
| 170 |
|
|
| 171 |
|
|
| 172 |
do_fetch() {
|
|
| 173 |
get_backups_with_duration | while read -r name duration messages; do |
|
| 174 |
print_backup_details "$name" "$duration" "$messages" |
|
| 175 |
done |
|
| 176 |
} |
|
| 177 |
|
|
| 178 |
|
|
| 179 |
case ${1:-} in
|
|
| 180 |
autoconf) |
|
| 181 |
do_autoconf |
|
| 182 |
;; |
|
| 183 |
config) |
|
| 184 |
do_config "${MUNIN_CAP_DIRTYCONFIG:-0}"
|
|
| 185 |
;; |
|
| 186 |
"") |
|
| 187 |
do_fetch |
|
| 188 |
;; |
|
| 189 |
*) |
|
| 190 |
echo >&2 "Unknown command: $1" |
|
| 191 |
exit 1 |
|
| 192 |
;; |
|
| 193 |
esac |
|
Formats disponibles : Unified diff