evobackup/lib/bkctld-stats

49 lines
1.6 KiB
Plaintext
Raw Normal View History

2019-01-04 13:51:05 +01:00
#!/bin/sh
#
# Make and display stats on jails (size, lastconn)
# 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
2019-01-04 13:51:05 +01:00
[ ! -f "${INDEX_DIR}/.lastrun.duc" ] && notice "First run of DUC always in progress ..." && exit 0
[ ! -f ${IDX_FILE} ] && error "Index file do not 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 "@{}"
echo "<jail> <size> <incs> <lastconn>" | awk '{ printf("%- 30s %- 10s %- 10s %- 15s\n", $1, $2, $3, $4); }'
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)
2020-04-02 01:07:12 +02:00
# shellcheck disable=SC2064
2019-01-04 13:51:05 +01:00
trap "rm ${duc_output} ${incs_output} ${stat_output}" 0
2020-04-02 01:07:12 +02:00
2019-01-04 13:51:05 +01:00
"${DUC}" ls -d "${IDX_FILE}" "${JAILDIR}" > "${duc_output}"
2020-04-02 01:07:12 +02:00
awk '{ print $2 }' "${duc_output}" | while read jail_name; do
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})
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
2019-01-04 13:51:05 +01:00
paste "${duc_output}" "${incs_output}" "${stat_output}" | awk '{ printf("%- 30s %- 10s %- 10s %- 15s\n", $2, $1, $3, $4); }'