statusExporters.sh 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. #!/usr/bin/env bash
  2. set -e
  3. cat << 'LOGO'
  4. ----------------------------------
  5. LOGO
  6. base_dir=$(
  7. cd "$(dirname "$0")"
  8. pwd
  9. )
  10. cd $base_dir
  11. echo -e "\n"
  12. # node_exporter
  13. node_exporter_pid=$(ps -auxc | grep node_exporter | grep -vE "grep|-Xmx700m" | awk '{print $2}')
  14. if [[ $node_exporter_pid == "" ]]; then
  15. echo "node_exporter未在运行"
  16. else
  17. running_time=$(ps -o etime= -p "$node_exporter_pid")
  18. ports=$(netstat -tnlp | grep node_e. | head -n +1 | awk '{print $4}')
  19. echo "node_exporter当前PID: $node_exporter_pid"
  20. echo "当前运行时间: $running_time" | tr -s " "
  21. echo "当前运行端口:"
  22. for i in "$ports"; do
  23. echo "$i"
  24. done
  25. fi
  26. # postgres_exporter
  27. echo -e "\n"
  28. postgres_exporter_pid=$(ps -auxc | grep postgres_export | grep -vE "grep|-Xmx700m" | awk '{print $2}')
  29. if [[ $postgres_exporter_pid == "" ]]; then
  30. echo "postgres_exporter未在运行"
  31. else
  32. running_time=$(ps -o etime= -p "$postgres_exporter_pid")
  33. ports=$(netstat -tnlp | grep redis_e. | head -n +1 | awk '{print $4}')
  34. echo "postgres_exporter当前PID: $postgres_exporter_pid"
  35. echo "当前运行时间: $running_time" | tr -s " "
  36. echo "当前运行端口:"
  37. for i in "$ports"; do
  38. echo "$i"
  39. done
  40. fi