node_dump 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. #!/bin/sh
  2. set -eu
  3. ROOT_DIR="$(cd "$(dirname "$(readlink "$0" || echo "$0")")"/..; pwd -P)"
  4. echo "Running node dump in ${ROOT_DIR}"
  5. # shellcheck disable=SC1090
  6. . "$ROOT_DIR"/releases/emqx_vars
  7. cd "${ROOT_DIR}"
  8. DUMP="$RUNNER_LOG_DIR/node_dump_$(date +"%Y%m%d_%H%M%S").tar.gz"
  9. CONF_DUMP="$RUNNER_LOG_DIR/conf.dump"
  10. SYSINFO="$RUNNER_LOG_DIR/sysinfo.txt"
  11. LOG_MAX_AGE_DAYS=3
  12. collect() {
  13. echo "========================================================"
  14. echo " $*"
  15. echo "========================================================"
  16. eval "$*" || echo "Unavailable"
  17. echo
  18. }
  19. show_help() {
  20. echo "Collect information about the EMQX node
  21. USAGE:
  22. $0 [-a DAYS]
  23. OPTIONS:
  24. -a n Set maximum age of collected log files in days (3 by default)"
  25. exit 1
  26. }
  27. while getopts "a:h" opt; do
  28. case "${opt}" in
  29. a) LOG_MAX_AGE_DAYS="${OPTARG}" ;;
  30. h) show_help ;;
  31. *) ;;
  32. esac
  33. done
  34. # Collect system info:
  35. {
  36. collect "$RUNNER_BIN_DIR"/emqx_ctl broker
  37. collect "$RUNNER_BIN_DIR"/emqx eval "'emqx_node_dump:sys_info()'"
  38. collect uname -a
  39. collect uptime
  40. collect free
  41. collect netstat -tnl
  42. collect "$RUNNER_BIN_DIR"/emqx_ctl plugins list
  43. collect "$RUNNER_BIN_DIR"/emqx_ctl modules list
  44. collect "$RUNNER_BIN_DIR"/emqx_ctl vm all
  45. collect "$RUNNER_BIN_DIR"/emqx_ctl listeners
  46. } > "${SYSINFO}"
  47. # Collect information about the configuration:
  48. {
  49. collect "$RUNNER_BIN_DIR"/emqx eval "'emqx_node_dump:app_env_dump()'"
  50. } > "${CONF_DUMP}"
  51. # Pack files
  52. {
  53. find "$RUNNER_LOG_DIR" -mtime -"${LOG_MAX_AGE_DAYS}" \( -name '*.log.*' -or -name 'run_erl.log*' \)
  54. echo "${SYSINFO}"
  55. echo "${CONF_DUMP}"
  56. } | tar czf "${DUMP}" -T -
  57. ## Cleanup:
  58. rm "${SYSINFO}"
  59. #rm "${CONF_DUMP}" # Keep it for inspection
  60. echo "Created a node dump ${DUMP}"
  61. echo
  62. echo "WARNING: this script tries to obfuscate secrets, but make sure to
  63. inspect log/conf.dump file manually before uploading the node dump
  64. to a public location."