-
Notifications
You must be signed in to change notification settings - Fork 0
/
borg-wrapper-munin
executable file
·77 lines (72 loc) · 2.21 KB
/
borg-wrapper-munin
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/bin/bash
set -o nounset
set -o errexit
DIR=$(dirname -- "$(readlink -f -- "$0")")
# loading the name of the config directory
source "${DIR}/borg-wrapper-conf"
BASE_CONF="${DIR_CONF}/conf"
source "${BASE_CONF}"
DEFAULT_WARNING="${MUNIN_WARNING}"
DEFAULT_CRITICAL="${MUNIN_CRITICAL}"
MUNIN_CONFIG=false
SCRIPT="ls -A ${DIR_MONITORING}/*"
function run {
if [ "$MUNIN_CONFIG" = true ]; then
echo 'graph_title Borg backups - time since last run'
echo 'graph_args --base 1000 -l 0'
echo 'graph_vlabel hours since last run'
echo 'graph_period hour'
echo 'graph_printf %4.2lf'
echo 'graph_category backup'
fi
DATE_VAL=$(date +"%s")
for _file in $(${SCRIPT}) ; do
_entry=$(<"$_file")
_name="$(basename -- $_file)"
_raw_date=`echo "$_entry" | awk -F "," '{print $1}'`
_expire_sec=$(echo "${_raw_date}" | xargs -I{} date -d {} +%s)
_diff_sec=$((DATE_VAL-_expire_sec))
_expire_h=`echo "scale=2; $_diff_sec/60/60" | bc | awk '{printf "%0.2f", $1}'`
if [ "$MUNIN_CONFIG" = true ]; then
MUNIN_WARNING="${DEFAULT_WARNING}"
MUNIN_CRITICAL="${DEFAULT_CRITICAL}"
repo_conf "$_name"
echo "_$_name.label $_name"
echo "_$_name.warning :$MUNIN_WARNING"
echo "_$_name.critical :$MUNIN_CRITICAL"
else
echo "_$_name.value $_expire_h"
fi
done
}
function duration {
if [ "$MUNIN_CONFIG" = true ]; then
echo 'graph_title Borg backups - duration'
echo 'graph_args --base 1000 -l 0'
echo 'graph_vlabel duration in secconds'
echo 'graph_period second'
echo 'graph_printf %3.2lf'
echo 'graph_category backup'
fi
for _file in $(${SCRIPT}) ; do
_entry=$(<"$_file")
_name="$(basename -- $_file)"
_duration=`echo "$_entry" | awk -F "," '{print $2}'`
#_duration_h=`echo "scale=2; $_duration/60" | bc | awk '{printf "%0.2f", $1}'`
if [ "$MUNIN_CONFIG" = true ]; then
echo "_$_name.label $_name"
else
echo "_$_name.value $_duration"
fi
done
}
if [ $# == 1 ] && [ "$1" = "config" ]; then
MUNIN_CONFIG=true
fi
CMD=${0##*borg-wrapper-munin}
if [ "$CMD" = "-duration" ]; then
duration
else
run
fi
exit 0