run.sh 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. #!/usr/bin/env bash
  2. set +u
  3. set -e
  4. # set -x
  5. base_dir=$(
  6. cd "$(dirname "$0")"
  7. pwd
  8. )
  9. cd $base_dir
  10. # ./auto_del_log.sh
  11. function log_warn() {
  12. local date=$(date "+%Y-%m-%d-%H:%M:%S")
  13. local para=$1
  14. echo "[WARN] $date $1" | tee -a "./log/run_log"
  15. }
  16. function log_info() {
  17. local date=$(date "+%Y-%m-%d-%H:%M:%S")
  18. local para=$1
  19. echo "[INFO] $date $1" | tee -a "./log/run_log"
  20. }
  21. function log_err() {
  22. local date=$(date "+%Y-%m-%d-%H:%M:%S")
  23. local para=$1
  24. echo "[ERROR] $date $1" | tee -a "./log/run_log"
  25. }
  26. node_exporter_log_path="./log/node_exporter/"
  27. postgres_exporter_log_path="./log/postgres_exporter/"
  28. # node_exporter section
  29. if ps -auxc | grep "node_exporter" | grep -v grep > /dev/null; then
  30. log_info "node_exporter 已在运行"
  31. elif [[ ! -f "./lib/node_exporter" ]]; then
  32. log_info "no node_exporter found, skip"
  33. else
  34. if [[ ! -d $node_exporter_log_path ]]; then
  35. mkdir -p "$node_exporter_log_path"
  36. fi
  37. log_node_exporter_file="node_exporter_$(date "+%Y-%m-%d-%H:%M:%S").log"
  38. ./lib/node_exporter &>> "${node_exporter_log_path}${log_node_exporter_file}" &
  39. sleep 1
  40. log_info "node_exporter 启动成功!"
  41. fi
  42. # blackbox_exporter section
  43. if ps -auxc | grep "blackbox_exporter" | grep -v grep > /dev/null; then
  44. log_info "blackbox_exporter 已在运行"
  45. elif [[ ! -f "./lib/blackbox_exporter" ]]; then
  46. log_info "no blackbox_exporter found, skip"
  47. else
  48. if [[ ! -d $blackbox_exporter_log_path ]]; then
  49. mkdir -p "$blackbox_exporter_log_path"
  50. fi
  51. log_blackbox_exporter_file="blackbox_exporter_$(date "+%Y-%m-%d-%H:%M:%S").log"
  52. ./lib/blackbox_exporter --config.file="./conf/blackbox.yml" --web.listen-address=:9115 &>> "${blackbox_exporter_log_path}${log_blackbox_exporter_file}" &
  53. sleep 1
  54. log_info "blackbox_exporter 启动成功!"
  55. fi