12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- #!/usr/bin/env bash
- set +u
- set -e
- # set -x
- base_dir=$(
- cd "$(dirname "$0")"
- pwd
- )
- cd $base_dir
- # ./auto_del_log.sh
- function log_warn() {
- local date=$(date "+%Y-%m-%d-%H:%M:%S")
- local para=$1
- echo "[WARN] $date $1" | tee -a "./log/run_log"
- }
- function log_info() {
- local date=$(date "+%Y-%m-%d-%H:%M:%S")
- local para=$1
- echo "[INFO] $date $1" | tee -a "./log/run_log"
- }
- function log_err() {
- local date=$(date "+%Y-%m-%d-%H:%M:%S")
- local para=$1
- echo "[ERROR] $date $1" | tee -a "./log/run_log"
- }
- node_exporter_log_path="./log/node_exporter/"
- postgres_exporter_log_path="./log/postgres_exporter/"
- # node_exporter section
- if ps -auxc | grep "node_exporter" | grep -v grep > /dev/null; then
- log_info "node_exporter 已在运行"
- elif [[ ! -f "./lib/node_exporter" ]]; then
- log_info "no node_exporter found, skip"
- else
- if [[ ! -d $node_exporter_log_path ]]; then
- mkdir -p "$node_exporter_log_path"
- fi
- log_node_exporter_file="node_exporter_$(date "+%Y-%m-%d-%H:%M:%S").log"
- ./lib/node_exporter &>> "${node_exporter_log_path}${log_node_exporter_file}" &
- sleep 1
- log_info "node_exporter 启动成功!"
- fi
- # blackbox_exporter section
- if ps -auxc | grep "blackbox_exporter" | grep -v grep > /dev/null; then
- log_info "blackbox_exporter 已在运行"
- elif [[ ! -f "./lib/blackbox_exporter" ]]; then
- log_info "no blackbox_exporter found, skip"
- else
- if [[ ! -d $blackbox_exporter_log_path ]]; then
- mkdir -p "$blackbox_exporter_log_path"
- fi
- log_blackbox_exporter_file="blackbox_exporter_$(date "+%Y-%m-%d-%H:%M:%S").log"
- ./lib/blackbox_exporter --config.file="./conf/blackbox.yml" --web.listen-address=:9115 &>> "${blackbox_exporter_log_path}${log_blackbox_exporter_file}" &
- sleep 1
- log_info "blackbox_exporter 启动成功!"
- fi
|