node_dump 1.7 KB

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