node_dump 1.8 KB

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