forked from evolix/evobackup
Add stats subcommands
This commit is contained in:
parent
ce674490f7
commit
f780d4d94a
2
Vagrantfile
vendored
2
Vagrantfile
vendored
|
@ -23,7 +23,7 @@ mkdir -p /usr/lib/nagios/plugins/
|
|||
SCRIPT
|
||||
|
||||
$deps = <<SCRIPT
|
||||
DEBIAN_FRONTEND=noninteractive apt-get -yq install openssh-server btrfs-tools rsync lsb-base coreutils sed dash mount openssh-sftp-server libc6 bash-completion
|
||||
DEBIAN_FRONTEND=noninteractive apt-get -yq install openssh-server btrfs-tools rsync lsb-base coreutils sed dash mount openssh-sftp-server libc6 bash-completion duc-nox
|
||||
SCRIPT
|
||||
|
||||
$pre_part = <<SCRIPT
|
||||
|
|
|
@ -9,7 +9,7 @@ function _bkctld()
|
|||
|
||||
cur=${COMP_WORDS[COMP_CWORD]};
|
||||
prev=${COMP_WORDS[COMP_CWORD-1]};
|
||||
commands="init update remove start stop reload restart sync status key port ip inc rm check"
|
||||
commands="init update remove start stop reload restart sync status key port ip inc rm check stats"
|
||||
|
||||
if [ $COMP_CWORD -eq 1 ]; then
|
||||
COMPREPLY=($(compgen -W '${commands}' -- ${cur}))
|
||||
|
|
25
bkctld
25
bkctld
|
@ -29,6 +29,7 @@ Subcommands:
|
|||
inc Make incremental inc of all jails
|
||||
rm Remove old incremtal inc of all jails
|
||||
check Run check on jails (NRPE output)
|
||||
stats Make and display stats on jails (size, lastconn)
|
||||
|
||||
EOF
|
||||
}
|
||||
|
@ -519,6 +520,23 @@ sub_check() {
|
|||
exit "${return}"
|
||||
}
|
||||
|
||||
sub_stats() {
|
||||
lsof "${IDX_FILE}" >/dev/null 2>&1 || nohup ionice -c3 "${DUC}" index -d "${IDX_FILE}" "${JAILDIR}" >/dev/null 2>&1 &
|
||||
timeout 10 sh -c -- "while [ ! -f ${IDX_FILE} ]; do sleep 1; done"
|
||||
[ ! -f ${IDX_FILE} ] && error "Index file do not exits !"
|
||||
printf "Last update of index file : "
|
||||
stat --format=%Y "${IDX_FILE}" | xargs -i -n1 date -R -d "@{}"
|
||||
echo "<jail> <size> <lastconn>" | awk '{ printf("%- 30s %- 20s %- 20s\n", $1, $2, $3); }'
|
||||
duc_output=$(mktemp)
|
||||
stat_output=$(mktemp)
|
||||
trap "rm ${duc_output} ${stat_output}" 0
|
||||
"${DUC}" ls -d "${IDX_FILE}" "${JAILDIR}" > "${duc_output}"
|
||||
awk '{ print $2 }' "${duc_output}" | while read jail; do
|
||||
stat --format=%Y "/backup/jails/${jail}/var/log/lastlog" | xargs -i -n1 date -d "@{}" "+%d-%m-%Y" >> "${stat_output}"
|
||||
done
|
||||
paste "${duc_output}" "${stat_output}" | awk '{ printf("%- 30s %- 20s %- 20s\n", $2, $1, $3); }'
|
||||
}
|
||||
|
||||
## main function : check usage and valid params
|
||||
|
||||
main() {
|
||||
|
@ -529,6 +547,8 @@ main() {
|
|||
JAILDIR="${JAILDIR:-/backup/jails}"
|
||||
INCDIR="${INCDIR:-/backup/incs}"
|
||||
TPLDIR="${TPLDIR:-/usr/share/bkctld}"
|
||||
INDEX_DIR="${INDEX_DIR:-/backup/index}"
|
||||
IDX_FILE="${IDX_FILE:-${INDEX_DIR}/bkctld-jails.idx}"
|
||||
LOCALTPLDIR="${LOCALTPLDIR:-/usr/local/share/bkctld}"
|
||||
SSHD_PID="${SSHD_PID:-/run/sshd.pid}"
|
||||
SSHD_CONFIG="${SSHD_CONFIG:-/etc/ssh/sshd_config}"
|
||||
|
@ -538,7 +558,8 @@ main() {
|
|||
CRITICAL="${CRITICAL:-48}"
|
||||
WARNING="${WARNING:-24}"
|
||||
BTRFS=$(command -v btrfs)
|
||||
mkdir -p "${CONFDIR}" "${JAILDIR}" "${INCDIR}"
|
||||
DUC=$(command -v duc-nox||command -v duc)
|
||||
mkdir -p "${CONFDIR}" "${JAILDIR}" "${INCDIR}" "${INDEX_DIR}"
|
||||
subcommand="${1:-}"
|
||||
jail="${2:-}"
|
||||
option="${3:-}"
|
||||
|
@ -546,7 +567,7 @@ main() {
|
|||
"" | "-h" | "--help")
|
||||
usage
|
||||
;;
|
||||
"inc" | "rm" | "check")
|
||||
"inc" | "rm" | "check" | "stats")
|
||||
"sub_${subcommand}"
|
||||
;;
|
||||
"init")
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
#JAILDIR='/backup/jails'
|
||||
#INCDIR='/backup/incs'
|
||||
#TPLDIR='/usr/share/bkctld'
|
||||
#INDEX_DIR='/backup/index'
|
||||
#LOCALTPLDIR='/usr/local/share/bkctld'
|
||||
#SSHD_PID='/var/run/sshd.pid'
|
||||
#SSHD_CONFIG='/etc/ssh/sshd_config'
|
||||
|
|
Loading…
Reference in a new issue