1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- #!/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
- # postgres_exporter section
- if ps -auxc | grep "postgres_exporter" | grep -v grep > /dev/null; then
- log_info "postgres_exporter 已在运行"
- elif [[ ! -f "./lib/postgres_exporter" ]]; then
- log_info "no postgres_exporter found, skip"
- else
- if [[ ! -d $postgres_exporter_log_path ]]; then
- mkdir -p "$postgres_exporter_log_path"
- fi
- log_postgres_exporter_file="postgres_exporter_$(date "+%Y-%m-%d-%H:%M:%S").log"
- ./lib/postgres_exporter --web.listen-address=:9187 &>> "${postgres_exporter_log_path}${log_postgres_exporter_file}" &
- sleep 1
- log_info "postgres_exporter 启动成功!"
- fi
|