add mysqld exporter
This commit is contained in:
@@ -93,6 +93,17 @@ WantedBy=multi-user.target
|
|||||||
|
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
|
# Create systemd service restart file
|
||||||
|
echo "Create systemd service restart file..."
|
||||||
|
sudo tee "/usr/bin/restart_prometheus" > /dev/null <<EOF
|
||||||
|
|
||||||
|
#!/bin/bash
|
||||||
|
systemctl daemon-reload
|
||||||
|
systemctl restart prometheus.service
|
||||||
|
systemctl status prometheus.service
|
||||||
|
|
||||||
|
EOF
|
||||||
|
sudo chmod 755 /usr/bin/restart_prometheus
|
||||||
# Reload systemd, enable and start service
|
# Reload systemd, enable and start service
|
||||||
echo "Enabling and starting Prometheus service..."
|
echo "Enabling and starting Prometheus service..."
|
||||||
sudo systemctl daemon-reload
|
sudo systemctl daemon-reload
|
||||||
|
|||||||
107
Prometheus/install_mysqld_exporter.sh
Normal file
107
Prometheus/install_mysqld_exporter.sh
Normal file
@@ -0,0 +1,107 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
set -e
|
||||||
|
|
||||||
|
#Detect Operation System
|
||||||
|
|
||||||
|
if command -v apt >/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 <<EOF
|
||||||
|
|
||||||
|
[client]
|
||||||
|
user=exporter
|
||||||
|
password=exporter_password
|
||||||
|
host=127.0.0.1
|
||||||
|
port=3306
|
||||||
|
|
||||||
|
EOF
|
||||||
|
|
||||||
|
# Create systemd service file
|
||||||
|
SERVICE_FILE="/etc/systemd/system/mysqld_exporter.service"
|
||||||
|
|
||||||
|
echo "Creating systemd service file..."
|
||||||
|
sudo tee "$SERVICE_FILE" > /dev/null <<EOF
|
||||||
|
|
||||||
|
[Unit]
|
||||||
|
Description=Prometheus MySQL Exporter
|
||||||
|
Documentation=https://github.com/prometheus/mysqld_exporter
|
||||||
|
Wants=network-online.target
|
||||||
|
After=network-online.target
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
Type=simple
|
||||||
|
User=mysqld_exporter
|
||||||
|
Group=mysqld_exporter
|
||||||
|
ExecStart=/usr/local/bin/mysqld_exporter \
|
||||||
|
--config.my-cnf=/etc/mysqld_exporter/my.cnf \
|
||||||
|
--web.listen-address=0.0.0.0:9104
|
||||||
|
Restart=always
|
||||||
|
RestartSec=5
|
||||||
|
NoNewPrivileges=true
|
||||||
|
PrivateTmp=true
|
||||||
|
ProtectSystem=full
|
||||||
|
ProtectHome=true
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=multi-user.target
|
||||||
|
|
||||||
|
EOF
|
||||||
|
|
||||||
|
# Reload systemd, enable and start service
|
||||||
|
echo "Enabling and starting mysqld_exporter service..."
|
||||||
|
sudo systemctl daemon-reload
|
||||||
|
sudo systemctl enable --now mysqld_exporter.service
|
||||||
|
|
||||||
|
echo "MySQL Exporter installation completed, listening on port 9104"
|
||||||
Reference in New Issue
Block a user