node_dump 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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 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-erl "'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."