From cc1475e152f0f505519705fb8f0db27c6e5e9e5d Mon Sep 17 00:00:00 2001 From: root Date: Fri, 30 May 2025 13:18:35 +0200 Subject: [PATCH] Nuevo script para Prometheus --- .apply-done | 0 install_proxmox_exporters.sh | 86 ++++++++++++++++++++++++++++++++++++ 2 files changed, 86 insertions(+) create mode 100644 .apply-done create mode 100755 install_proxmox_exporters.sh diff --git a/.apply-done b/.apply-done new file mode 100644 index 0000000..e69de29 diff --git a/install_proxmox_exporters.sh b/install_proxmox_exporters.sh new file mode 100755 index 0000000..c4f2688 --- /dev/null +++ b/install_proxmox_exporters.sh @@ -0,0 +1,86 @@ +#!/bin/bash + +set -e + +# === VARIABLES === +NODE_EXPORTER_VERSION="1.8.1" +EXPORTERS_DIR="/opt/proxmox-exporters" +PROXMOX_API_USER="root@pam" # CAMBIA ESTO si usas otro usuario +PROXMOX_API_PASSWORD="Goleador28092310" # CAMBIA ESTO +PROXMOX_API_HOST="https://localhost:8006" + +# === Node Exporter === +echo "[*] Instalando node_exporter..." + +mkdir -p $EXPORTERS_DIR +cd $EXPORTERS_DIR + +wget -q https://github.com/prometheus/node_exporter/releases/download/v${NODE_EXPORTER_VERSION}/node_exporter-${NODE_EXPORTER_VERSION}.linux-amd64.tar.gz +tar -xzf node_exporter-${NODE_EXPORTER_VERSION}.linux-amd64.tar.gz +cp -f node_exporter-${NODE_EXPORTER_VERSION}.linux-amd64/node_exporter /usr/local/bin/ + +cat </etc/systemd/system/node_exporter.service +[Unit] +Description=Prometheus Node Exporter +After=network.target + +[Service] +User=nobody +ExecStart=/usr/local/bin/node_exporter +Restart=on-failure + +[Install] +WantedBy=multi-user.target +EOF + +systemctl daemon-reexec +systemctl enable --now node_exporter +echo "[✔] node_exporter instalado en el puerto 9100" + +# === Proxmox Exporter === +echo "[*] Instalando prometheus-pve-exporter..." + +apt update -qq && apt install -y python3-venv git + +cd $EXPORTERS_DIR +git clone https://github.com/prometheus-pve/prometheus-pve-exporter.git +cd prometheus-pve-exporter +python3 -m venv venv +source venv/bin/activate +pip install . + +cat <config.yaml +proxmox: + url: "$PROXMOX_API_HOST" + user: "$PROXMOX_API_USER" + password: "$PROXMOX_API_PASSWORD" + verify_ssl: false + +listen: + address: "0.0.0.0" + port: 9221 +EOF + +cat </etc/systemd/system/prometheus-pve-exporter.service +[Unit] +Description=Proxmox VE Exporter +After=network.target + +[Service] +WorkingDirectory=$EXPORTERS_DIR/prometheus-pve-exporter +ExecStart=$EXPORTERS_DIR/prometheus-pve-exporter/venv/bin/prometheus-pve-exporter -c config.yaml +Restart=on-failure + +[Install] +WantedBy=multi-user.target +EOF + +systemctl daemon-reexec +systemctl enable --now prometheus-pve-exporter +echo "[✔] prometheus-pve-exporter instalado en el puerto 9221" + +# === Fin === +echo "" +echo "✅ Exporters desplegados:" +echo " - http://$(hostname -I | awk '{print $1}'):9100/metrics" +echo " - http://$(hostname -I | awk '{print $1}'):9221/metrics"