node_dump 2.0 KB

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