From 3f55309527f797e6d8b09c393c318955acc258a0 Mon Sep 17 00:00:00 2001 From: CN-JS-HuiBai Date: Sun, 25 Jan 2026 14:17:42 +0800 Subject: [PATCH] add mysqld exporter --- Prometheus/install_Prometheus.sh | 11 +++ Prometheus/install_mysqld_exporter.sh | 107 ++++++++++++++++++++++++++ 2 files changed, 118 insertions(+) create mode 100644 Prometheus/install_mysqld_exporter.sh diff --git a/Prometheus/install_Prometheus.sh b/Prometheus/install_Prometheus.sh index 8ec4beb..c0b00c6 100644 --- a/Prometheus/install_Prometheus.sh +++ b/Prometheus/install_Prometheus.sh @@ -93,6 +93,17 @@ WantedBy=multi-user.target EOF +# Create systemd service restart file +echo "Create systemd service restart file..." +sudo tee "/usr/bin/restart_prometheus" > /dev/null </dev/null 2>&1; then + echo "Detected apt-based system" + sudo apt update + sudo apt install -y wget curl tar + +elif command -v dnf >/dev/null 2>&1; then + echo "Detected dnf-based system" + sudo dnf install -y wget curl tar + +else + echo "Unsupported package manager" + exit 1 +fi + + +# Download Node Exporter + +CN_URL="https://8.134.128.173/relayx/node_exporter-1.10.2.linux-amd64.tar.gz" +GLOBAL_URL="https://github.com/prometheus/mysqld_exporter/releases/download/v0.18.0/mysqld_exporter-0.18.0.linux-amd64.tar.gz" +TARGET="/tmp/mysqld_exporter-0.18.0.linux-amd64.tar.gz" + +is_cn=false + +echo "Detecting geographic location..." + +COUNTRY=$(curl -s --max-time 3 https://ipinfo.io/country || true) +if [ "$COUNTRY" = "CN" ]; then + is_cn=true +fi + + +if [ "$is_cn" = true ]; then + echo "Geolocation: China mainland detected" + DOWNLOAD_URL="$CN_URL" +else + echo "Geolocation: non-China region detected" + DOWNLOAD_URL="$GLOBAL_URL" +fi + +echo "Downloading from: $DOWNLOAD_URL" +curl -fL -o "$TARGET" "$DOWNLOAD_URL" + + +sudo mkdir -p /etc/mysqld_exporter + + +# Extract +echo "Extracting Node Exporter..." +tar -zxvf /tmp/mysqld_exporter-0.18.0.linux-amd64.tar.gz -C /tmp + +# Copy to /node_exporter +echo "Copying Node Exporter to /node_exporter..." +sudo cp -r /tmp/mysqld_exporter-0.18.0.linux-amd64.tar.gz/mysqld_exporter /usr/bin/mysqld_exporter + +# Create mysqld_exporter config +sudo tee "/etc/mysqld_exporter/my.cnf" > /dev/null < /dev/null <