evobackup/server/lib/bkctld-stats

54 lines
1.7 KiB
Plaintext
Raw Normal View History

2019-01-04 13:51:05 +01:00
#!/bin/sh
#
# Description: Display stats on jails (size, last connection…)
# Usage: stats
#
2019-01-04 13:51:05 +01:00
2020-04-02 13:44:13 +02:00
# shellcheck source=./includes
2020-04-02 00:31:57 +02:00
LIBDIR="$(dirname $0)" && . "${LIBDIR}/includes"
2019-01-04 13:51:05 +01:00
2019-01-08 16:29:03 +01:00
mkdir -p "${INDEX_DIR}"
2020-04-02 01:07:12 +02:00
2019-01-04 13:51:05 +01:00
lsof "${IDX_FILE}" >/dev/null 2>&1 || nohup sh -s -- <<EOF >/dev/null 2>&1 &
2020-04-02 01:07:12 +02:00
2019-01-07 16:11:57 +01:00
ionice -c3 "${DUC}" index -d "${IDX_FILE}" "${JAILDIR}"
2019-01-04 13:51:05 +01:00
touch "${INDEX_DIR}/.lastrun.duc"
EOF
2020-04-02 01:07:12 +02:00
2022-11-23 12:56:22 +01:00
[ ! -f "${INDEX_DIR}/.lastrun.duc" ] && notice "First run of DUC still in progress ..." && exit 0
2020-05-01 09:51:47 +02:00
[ ! -f ${IDX_FILE} ] && error "Index file doesn't exits !"
2020-04-02 01:07:12 +02:00
2019-01-04 13:51:05 +01:00
printf "Last update of index file : "
stat --format=%Y "${INDEX_DIR}/.lastrun.duc" | xargs -i -n1 date -R -d "@{}"
2020-04-02 01:07:12 +02:00
2019-01-04 13:51:05 +01:00
duc_output=$(mktemp)
stat_output=$(mktemp)
incs_output=$(mktemp)
jail_patterns_list=$(mktemp)
2020-04-02 01:07:12 +02:00
# shellcheck disable=SC2064
trap "rm ${duc_output} ${incs_output} ${stat_output} ${jail_patterns_list}" 0
2020-04-02 01:07:12 +02:00
"${DUC}" ls --database "${IDX_FILE}" "${JAILDIR}" > "${duc_output}"
2020-04-02 01:07:12 +02:00
jails_list | sed -e "s/^\(.*\)$/\\\\b\1\\\\b/" > "${jail_patterns_list}"
grep -f "${jail_patterns_list}" "${duc_output}" | awk '{ print $2 }' | while read jail_name; do
2020-04-02 01:07:12 +02:00
jail_path=$(jail_path "${jail_name}")
stat --format=%Y "${jail_path}/var/log/lastlog" | xargs -i -n1 date -d "@{}" "+%d-%m-%Y" >> "${stat_output}"
2020-04-02 23:52:27 +02:00
incs_policy_file=$(current_jail_incs_policy_file "${jail_name}")
2020-04-02 23:52:27 +02:00
incs_policy="0"
if [ -r "${incs_policy_file}" ]; then
days=$(grep "^\+" "${incs_policy_file}" | grep --count "day")
months=$(grep "^\+" "${incs_policy_file}" | grep --count "month")
incs_policy="${days}/${months}"
2019-01-07 16:12:51 +01:00
fi
2020-04-02 23:52:27 +02:00
echo "${incs_policy}" >> "${incs_output}"
2019-01-04 13:51:05 +01:00
done
2020-04-02 01:07:12 +02:00
(
echo "<jail> <size> <incs> <lastconn>"
paste "${duc_output}" "${incs_output}" "${stat_output}" | awk '{ printf("%s %s %s %s\n", $2, $1, $3, $4); }'
) | column -t