initial commit
This commit is contained in:
80
deploy_exporters.sh
Normal file
80
deploy_exporters.sh
Normal file
@@ -0,0 +1,80 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
WEBHOOK_URL="https://text.seekright.com/hooks/6a0eb41ea88367bc6e101f0c/gvXfD8zSNRti43kEabqdE9tMCvNi9zAAoGfbao7cxcKbiW6R"
|
||||
HOSTNAME=$(hostname)
|
||||
|
||||
notify() {
|
||||
curl -s -X POST "$WEBHOOK_URL" \
|
||||
-H 'Content-Type: application/json' \
|
||||
-d "{\"text\": \"$1\"}" > /dev/null 2>&1
|
||||
}
|
||||
|
||||
trap 'notify "❌ *FAILED* on *${HOSTNAME}* — script crashed at line $LINENO. Check the machine manually."' ERR
|
||||
|
||||
echo "Starting Automated Exporter Installation..."
|
||||
if [ "$EUID" -ne 0 ]; then echo "❌ Error: Please run this script with sudo."; exit 1; fi
|
||||
NODE_VERSION="1.7.0"
|
||||
GPU_VERSION="1.4.1"
|
||||
echo "======================================"
|
||||
echo "1. Installing Node Exporter v${NODE_VERSION}"
|
||||
echo "======================================"
|
||||
cd /tmp
|
||||
wget -q https://github.com/prometheus/node_exporter/releases/download/v${NODE_VERSION}/node_exporter-${NODE_VERSION}.linux-amd64.tar.gz
|
||||
tar -xf node_exporter-${NODE_VERSION}.linux-amd64.tar.gz
|
||||
if ! id "node_exporter" &>/dev/null; then useradd --no-create-home --shell /bin/false node_exporter; fi
|
||||
cp node_exporter-${NODE_VERSION}.linux-amd64/node_exporter /usr/local/bin/
|
||||
chown node_exporter:node_exporter /usr/local/bin/node_exporter
|
||||
cat << 'EOF' > /etc/systemd/system/node_exporter.service
|
||||
[Unit]
|
||||
Description=Node Exporter
|
||||
Wants=network-online.target
|
||||
After=network-online.target
|
||||
[Service]
|
||||
User=node_exporter
|
||||
Group=node_exporter
|
||||
Type=simple
|
||||
ExecStart=/usr/local/bin/node_exporter
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
EOF
|
||||
systemctl daemon-reload
|
||||
systemctl enable --now node_exporter
|
||||
echo "✅ Node Exporter installed and running on port 9100!"
|
||||
echo "======================================"
|
||||
echo "2. Checking for Nvidia GPU..."
|
||||
echo "======================================"
|
||||
GPU_STATUS="No GPU detected"
|
||||
if command -v nvidia-smi &> /dev/null; then
|
||||
echo "Nvidia GPU detected! Installing Nvidia GPU Exporter v${GPU_VERSION}..."
|
||||
wget -q https://github.com/utkuozdemir/nvidia_gpu_exporter/releases/download/v${GPU_VERSION}/nvidia_gpu_exporter_${GPU_VERSION}_linux_x86_64.tar.gz
|
||||
tar -xf nvidia_gpu_exporter_${GPU_VERSION}_linux_x86_64.tar.gz
|
||||
if ! id "nvidia_exporter" &>/dev/null; then useradd --no-create-home --shell /bin/false nvidia_exporter; fi
|
||||
cp nvidia_gpu_exporter /usr/local/bin/
|
||||
chown nvidia_exporter:nvidia_exporter /usr/local/bin/nvidia_gpu_exporter
|
||||
cat << 'EOF' > /etc/systemd/system/nvidia_gpu_exporter.service
|
||||
[Unit]
|
||||
Description=Nvidia GPU Exporter
|
||||
Wants=network-online.target
|
||||
After=network-online.target
|
||||
[Service]
|
||||
User=nvidia_exporter
|
||||
Group=nvidia_exporter
|
||||
Type=simple
|
||||
ExecStart=/usr/local/bin/nvidia_gpu_exporter
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
EOF
|
||||
systemctl daemon-reload
|
||||
systemctl enable --now nvidia_gpu_exporter
|
||||
GPU_STATUS="✅ GPU Exporter running on port 9835"
|
||||
echo "✅ Nvidia GPU Exporter installed and running on port 9835!"
|
||||
else
|
||||
echo "No Nvidia GPU detected. Skipping GPU Exporter installation."
|
||||
fi
|
||||
echo "======================================"
|
||||
echo "🎉 Installation Complete!"
|
||||
echo "Node Exporter is listening on port 9100"
|
||||
echo "======================================"
|
||||
|
||||
notify "✅ *SUCCESS* on *${HOSTNAME}* | Node Exporter: :9100 | GPU Exporter: ${GPU_STATUS}"
|
||||
Reference in New Issue
Block a user