Volver al blog
VPS e Infraestructura2026-10-01

Grafana en un VPS: instalar Prometheus y el panel en Ubuntu

Grafana en un VPS Ubuntu: instale Node Exporter, Prometheus y el panel de CPU, memoria, disco y red, con el acceso cerrado en el firewall.

Grafana en un VPS es el panel que lee las métricas que Prometheus recoge en ese servidor: CPU, memoria, disco y red. Sin ese historial, el equipo descubre que el disco se llenó cuando la aplicación ya está caída.

Esta guía instala Node Exporter, Prometheus y Grafana en Ubuntu 22.04 o 24.04. Las versiones fijadas son Prometheus 2.53.0 y Node Exporter 1.8.2. Antes de copiar los comandos, confirme que siguen siendo las estables en github.com/prometheus/prometheus/releases.

El concepto del stack está en monitoreo con Prometheus y Grafana. El servidor puede ser un VPS KVM gestionado.

1. Crear los usuarios de servicio

Los binarios no deben ejecutarse como root.

sudo useradd --no-create-home --shell /usr/sbin/nologin prometheus
sudo useradd --no-create-home --shell /usr/sbin/nologin node_exporter

2. Instalar Node Exporter

Node Exporter publica las métricas del sistema en el puerto 9100.

cd /tmp
NODE_VERSION=1.8.2
wget https://github.com/prometheus/node_exporter/releases/download/v${NODE_VERSION}/node_exporter-${NODE_VERSION}.linux-amd64.tar.gz
tar xzf node_exporter-${NODE_VERSION}.linux-amd64.tar.gz
sudo mv node_exporter-${NODE_VERSION}.linux-amd64/node_exporter /usr/local/bin/
sudo chown node_exporter:node_exporter /usr/local/bin/node_exporter

Cree /etc/systemd/system/node_exporter.service:

[Unit]
Description=Node Exporter
After=network.target

[Service]
User=node_exporter
Group=node_exporter
Type=simple
ExecStart=/usr/local/bin/node_exporter

[Install]
WantedBy=multi-user.target
sudo systemctl daemon-reload
sudo systemctl enable --now node_exporter
curl -s localhost:9100/metrics | head

El último comando tiene que imprimir métricas (node_cpu_seconds_total o similar). Si curl falla, ejecute systemctl status node_exporter.

3. Instalar Prometheus

cd /tmp
PROM_VERSION=2.53.0
wget https://github.com/prometheus/prometheus/releases/download/v${PROM_VERSION}/prometheus-${PROM_VERSION}.linux-amd64.tar.gz
tar xzf prometheus-${PROM_VERSION}.linux-amd64.tar.gz
sudo mv prometheus-${PROM_VERSION}.linux-amd64/prometheus prometheus-${PROM_VERSION}.linux-amd64/promtool /usr/local/bin/
sudo mkdir -p /etc/prometheus /var/lib/prometheus
sudo chown -R prometheus:prometheus /etc/prometheus /var/lib/prometheus

Guarde /etc/prometheus/prometheus.yml:

global:
  scrape_interval: 15s

scrape_configs:
  - job_name: prometheus
    static_configs:
      - targets: ["localhost:9090"]
  - job_name: node
    static_configs:
      - targets: ["localhost:9100"]
sudo chown prometheus:prometheus /etc/prometheus/prometheus.yml

Cree /etc/systemd/system/prometheus.service:

[Unit]
Description=Prometheus
After=network.target

[Service]
User=prometheus
Group=prometheus
Type=simple
ExecStart=/usr/local/bin/prometheus \
  --config.file=/etc/prometheus/prometheus.yml \
  --storage.tsdb.path=/var/lib/prometheus

[Install]
WantedBy=multi-user.target
sudo systemctl daemon-reload
sudo systemctl enable --now prometheus
curl -s localhost:9090/-/ready

La respuesta esperada es Prometheus Server is Ready.

4. Instalar Grafana e importar el panel

sudo apt-get install -y apt-transport-https wget
sudo mkdir -p /etc/apt/keyrings/
wget -q -O - https://apt.grafana.com/gpg.key | gpg --dearmor | sudo tee /etc/apt/keyrings/grafana.gpg > /dev/null
echo "deb [signed-by=/etc/apt/keyrings/grafana.gpg] https://apt.grafana.com stable main" | sudo tee /etc/apt/sources.list.d/grafana.list
sudo apt-get update
sudo apt-get install -y grafana

Deje el panel en la interfaz local. En /etc/grafana/grafana.ini, en la sección [server]:

http_addr = 127.0.0.1
http_port = 3000
sudo systemctl enable --now grafana-server

Desde su equipo, abra un túnel y entre en http://127.0.0.1:3000:

ssh -L 3000:127.0.0.1:3000 deploy@IP_DEL_VPS

Login inicial: admin / admin. Cambie la contraseña en el primer acceso. En Connections, Data sources, añada Prometheus con la URL http://127.0.0.1:9090. En Dashboards, New, Import, use el ID 1860 (Node Exporter Full) y seleccione esa fuente.

5. Firewall

Prometheus (9090) y Node Exporter (9100) quedan solo en localhost en esta guía. No publique esos puertos en internet. Si SSH todavía no está permitido en el firewall, hágalo antes de activarlo:

sudo ufw allow OpenSSH
sudo ufw enable
sudo ufw status

Conclusión

Con el panel 1860 abierto por el túnel SSH, el VPS tiene historial de CPU, memoria, disco y red. El siguiente paso operativo es una alerta: disco por encima del 80 % y load por encima del número de vCPU. Quien no quiera mantener este stack puede dejar el monitoreo en un VPS gestionado, donde la ingeniería sigue las mismas señales.

Servidor VPS KVM gestionado

ExpertCore levanta y administra el VPS: KVM aislado, copias de seguridad y soporte de ingeniería.

Ver planes de VPS