dgiot/bin/node_dump

85 lines
2.0 KiB
Plaintext
Raw Normal View History

2021-05-18 14:54:48 +08:00
#!/bin/sh
set -eu
2022-12-29 18:13:09 +08:00
RUNNER_ROOT_DIR="$(cd "$(dirname "$(readlink "$0" || echo "$0")")"/..; pwd -P)"
echo "Running node dump in ${RUNNER_ROOT_DIR}"
2021-05-18 14:54:48 +08:00
2022-12-29 18:13:09 +08:00
# shellcheck disable=SC1090
. "$RUNNER_ROOT_DIR"/releases/emqx_vars
2021-05-18 14:54:48 +08:00
2022-12-29 18:13:09 +08:00
cd "${RUNNER_ROOT_DIR}"
2021-05-18 14:54:48 +08:00
2022-12-29 18:13:09 +08:00
DUMP="$RUNNER_LOG_DIR/node_dump_$(date +"%Y%m%d_%H%M%S").tar.gz"
CONF_DUMP="$RUNNER_LOG_DIR/conf.dump"
SYSINFO="$RUNNER_LOG_DIR/sysinfo.txt"
2021-05-18 14:54:48 +08:00
LOG_MAX_AGE_DAYS=3
collect() {
echo "========================================================"
echo " $*"
echo "========================================================"
eval "$*" || echo "Unavailable"
echo
}
show_help() {
2022-12-29 18:13:09 +08:00
echo "Collect information about the EMQX node
2021-05-18 14:54:48 +08:00
USAGE:
2022-12-29 18:13:09 +08:00
$0 [-a DAYS]
2021-05-18 14:54:48 +08:00
OPTIONS:
-a n Set maximum age of collected log files in days (3 by default)"
exit 1
}
while getopts "a:h" opt; do
case "${opt}" in
a) LOG_MAX_AGE_DAYS="${OPTARG}" ;;
h) show_help ;;
*) ;;
esac
done
# Collect system info:
{
2022-12-29 18:13:09 +08:00
collect "$RUNNER_BIN_DIR"/emqx_ctl broker
collect "$RUNNER_BIN_DIR"/emqx eval "'emqx_node_dump:sys_info()'"
2021-05-18 14:54:48 +08:00
collect uname -a
collect uptime
collect free
collect netstat -tnl
2022-12-29 18:13:09 +08:00
collect "$RUNNER_BIN_DIR"/emqx_ctl plugins list
collect "$RUNNER_BIN_DIR"/emqx_ctl modules list
2021-05-18 14:54:48 +08:00
2022-12-29 18:13:09 +08:00
collect "$RUNNER_BIN_DIR"/emqx_ctl vm all
collect "$RUNNER_BIN_DIR"/emqx_ctl listeners
2021-05-18 14:54:48 +08:00
} > "${SYSINFO}"
# Collect information about the configuration:
{
2022-12-29 18:13:09 +08:00
collect "$RUNNER_BIN_DIR"/emqx eval "'emqx_node_dump:app_env_dump()'"
2021-05-18 14:54:48 +08:00
} > "${CONF_DUMP}"
# Pack files
{
2022-12-29 18:13:09 +08:00
find "$RUNNER_LOG_DIR" -mtime -"${LOG_MAX_AGE_DAYS}" \( -name '*.log.*' -or -name 'run_erl.log*' \)
2021-05-18 14:54:48 +08:00
echo "${SYSINFO}"
echo "${CONF_DUMP}"
} | tar czf "${DUMP}" -T -
## Cleanup:
rm "${SYSINFO}"
#rm "${CONF_DUMP}" # Keep it for inspection
echo "Created a node dump ${DUMP}"
echo
echo "WARNING: this script tries to obfuscate secrets, but make sure to
inspect log/conf.dump file manually before uploading the node dump
to a public location."