Prerequisites & VPS Selection
💡 Tip: Storage needs grow with retention period. Plan ~2GB per day for 100 active time series with 15s scrape interval.
Install Prometheus
Update your system and create a dedicated user for Prometheus:
# Update system packages
sudo apt update && sudo apt upgrade -y
# Create prometheus user (no login shell)
sudo useradd --no-create-home --shell /bin/false prometheus
# Create directories
sudo mkdir -p /etc/prometheus
sudo mkdir -p /var/lib/prometheus
# Set ownership
sudo chown prometheus:prometheus /etc/prometheus
sudo chown prometheus:prometheus /var/lib/prometheusDownload and install the latest Prometheus release:
# Download Prometheus (check prometheus.io for latest version)
cd /tmp
PROM_VERSION="2.48.0"
wget https://github.com/prometheus/prometheus/releases/download/v${PROM_VERSION}/prometheus-${PROM_VERSION}.linux-amd64.tar.gz
# Extract the archive
tar xvfz prometheus-${PROM_VERSION}.linux-amd64.tar.gz
cd prometheus-${PROM_VERSION}.linux-amd64
# Copy binaries
sudo cp prometheus /usr/local/bin/
sudo cp promtool /usr/local/bin/
# Set ownership
sudo chown prometheus:prometheus /usr/local/bin/prometheus
sudo chown prometheus:prometheus /usr/local/bin/promtool
# Copy console libraries
sudo cp -r consoles /etc/prometheus
sudo cp -r console_libraries /etc/prometheus
sudo chown -R prometheus:prometheus /etc/prometheus/consoles
sudo chown -R prometheus:prometheus /etc/prometheus/console_libraries
# Verify installation
prometheus --versionConfigure Prometheus
Create the main Prometheus configuration file:
sudo nano /etc/prometheus/prometheus.ymlglobal:
scrape_interval: 15s
evaluation_interval: 15s
external_labels:
monitor: 'prometheus-server'
# Alertmanager configuration (optional)
alerting:
alertmanagers:
- static_configs:
- targets:
# - alertmanager:9093
# Load rules once and periodically evaluate them
rule_files:
# - "alert_rules.yml"
# Scrape configurations
scrape_configs:
# Monitor Prometheus itself
- job_name: 'prometheus'
static_configs:
- targets: ['localhost:9090']
# Monitor the local machine with Node Exporter
- job_name: 'node'
static_configs:
- targets: ['localhost:9100']sudo chown prometheus:prometheus /etc/prometheus/prometheus.yml
# Validate the configuration
promtool check config /etc/prometheus/prometheus.ymlInstall Node Exporter
Node Exporter collects hardware and OS metrics from your server:
# Create node_exporter user
sudo useradd --no-create-home --shell /bin/false node_exporter
# Download Node Exporter
cd /tmp
NODE_VERSION="1.7.0"
wget https://github.com/prometheus/node_exporter/releases/download/v${NODE_VERSION}/node_exporter-${NODE_VERSION}.linux-amd64.tar.gz
# Extract and install
tar xvfz node_exporter-${NODE_VERSION}.linux-amd64.tar.gz
sudo cp node_exporter-${NODE_VERSION}.linux-amd64/node_exporter /usr/local/bin/
sudo chown node_exporter:node_exporter /usr/local/bin/node_exportersudo nano /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 \
--collector.systemd \
--collector.processes
[Install]
WantedBy=multi-user.targetsudo systemctl daemon-reload
sudo systemctl start node_exporter
sudo systemctl enable node_exporter
sudo systemctl status node_exporterCreate Prometheus Systemd Service
sudo nano /etc/systemd/system/prometheus.service[Unit]
Description=Prometheus Monitoring
Wants=network-online.target
After=network-online.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/ \
--web.console.templates=/etc/prometheus/consoles \
--web.console.libraries=/etc/prometheus/console_libraries \
--web.listen-address=0.0.0.0:9090 \
--storage.tsdb.retention.time=30d \
--web.enable-lifecycle
ExecReload=/bin/kill -HUP $MAINPID
Restart=on-failure
[Install]
WantedBy=multi-user.targetsudo systemctl daemon-reload
sudo systemctl start prometheus
sudo systemctl enable prometheus
sudo systemctl status prometheus✅ Success! Prometheus is now accessible at http://YOUR_SERVER_IP:9090
Configure Nginx Reverse Proxy
# Install Nginx and apache2-utils for htpasswd
sudo apt install nginx apache2-utils -y
# Create password file (replace 'admin' with your username)
sudo htpasswd -c /etc/nginx/.htpasswd admin
# Create Nginx configuration
sudo nano /etc/nginx/sites-available/prometheusserver {
listen 80;
server_name prometheus.yourdomain.com;
location / {
auth_basic "Prometheus";
auth_basic_user_file /etc/nginx/.htpasswd;
proxy_pass http://localhost:9090;
proxy_http_version 1.1;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}sudo ln -s /etc/nginx/sites-available/prometheus /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl restart nginxSSL Certificate with Let's Encrypt
# Install Certbot
sudo apt install certbot python3-certbot-nginx -y
# Obtain SSL certificate
sudo certbot --nginx -d prometheus.yourdomain.com
# Verify auto-renewal
sudo certbot renew --dry-runConfigure Alerting Rules
Create alert rules for common monitoring scenarios:
sudo nano /etc/prometheus/alert_rules.ymlgroups:
- name: node_alerts
rules:
# High CPU usage alert
- alert: HighCPUUsage
expr: 100 - (avg by(instance) (rate(node_cpu_seconds_total{mode="idle"}[5m])) * 100) > 80
for: 5m
labels:
severity: warning
annotations:
summary: "High CPU usage on {{ $labels.instance }}"
description: "CPU usage is above 80% for more than 5 minutes."
# High memory usage alert
- alert: HighMemoryUsage
expr: (1 - (node_memory_MemAvailable_bytes / node_memory_MemTotal_bytes)) * 100 > 85
for: 5m
labels:
severity: warning
annotations:
summary: "High memory usage on {{ $labels.instance }}"
# Disk space running low
- alert: DiskSpaceLow
expr: (node_filesystem_avail_bytes{mountpoint="/"} / node_filesystem_size_bytes{mountpoint="/"}) * 100 < 15
for: 5m
labels:
severity: critical
annotations:
summary: "Low disk space on {{ $labels.instance }}"
# Instance down alert
- alert: InstanceDown
expr: up == 0
for: 1m
labels:
severity: critical
annotations:
summary: "Instance {{ $labels.instance }} down"# Edit prometheus.yml and uncomment: rule_files: ["alert_rules.yml"]
sudo nano /etc/prometheus/prometheus.yml
# Set ownership
sudo chown prometheus:prometheus /etc/prometheus/alert_rules.yml
# Validate rules
promtool check rules /etc/prometheus/alert_rules.yml
# Reload Prometheus configuration
curl -X POST http://localhost:9090/-/reloadMonitoring Examples
Monitor Multiple Servers
# In prometheus.yml, update the node job:
scrape_configs:
- job_name: 'node'
static_configs:
- targets:
- 'server1.example.com:9100'
- 'server2.example.com:9100'
- '192.168.1.10:9100'
labels:
env: 'production'
- targets:
- 'staging1.example.com:9100'
labels:
env: 'staging'Monitor Docker Containers
# Run cAdvisor as a container
docker run -d \
--name=cadvisor \
--privileged \
-p 8080:8080 \
-v /:/rootfs:ro \
-v /var/run:/var/run:ro \
-v /sys:/sys:ro \
-v /var/lib/docker/:/var/lib/docker:ro \
gcr.io/cadvisor/cadvisor:latest - job_name: 'cadvisor'
static_configs:
- targets: ['localhost:8080']Monitor HTTP Endpoints (Blackbox)
# Download and install blackbox_exporter
wget https://github.com/prometheus/blackbox_exporter/releases/download/v0.24.0/blackbox_exporter-0.24.0.linux-amd64.tar.gz
tar xvfz blackbox_exporter-0.24.0.linux-amd64.tar.gz
sudo cp blackbox_exporter-0.24.0.linux-amd64/blackbox_exporter /usr/local/bin/
sudo cp blackbox_exporter-0.24.0.linux-amd64/blackbox.yml /etc/prometheus/
# Start blackbox exporter
blackbox_exporter --config.file=/etc/prometheus/blackbox.yml & - job_name: 'blackbox-http'
metrics_path: /probe
params:
module: [http_2xx]
static_configs:
- targets:
- https://example.com
- https://api.example.com/health
relabel_configs:
- source_labels: [__address__]
target_label: __param_target
- source_labels: [__param_target]
target_label: instance
- target_label: __address__
replacement: localhost:9115Monitor MySQL/MariaDB
# Create MySQL user for exporter
mysql -u root -p -e "
CREATE USER 'exporter'@'localhost' IDENTIFIED BY 'your_password';
GRANT PROCESS, REPLICATION CLIENT, SELECT ON *.* TO 'exporter'@'localhost';
FLUSH PRIVILEGES;"
# Create credentials file
cat > /etc/.mysqld_exporter.cnf << EOF
[client]
user=exporter
password=your_password
EOF
# Download and run mysqld_exporter
wget https://github.com/prometheus/mysqld_exporter/releases/download/v0.15.1/mysqld_exporter-0.15.1.linux-amd64.tar.gz
tar xvfz mysqld_exporter-0.15.1.linux-amd64.tar.gz
./mysqld_exporter --config.my-cnf=/etc/.mysqld_exporter.cnf & - job_name: 'mysql'
static_configs:
- targets: ['localhost:9104']Grafana Integration
# Install Grafana
sudo apt-get install -y apt-transport-https software-properties-common wget
wget -q -O - https://packages.grafana.com/gpg.key | sudo apt-key add -
echo "deb https://packages.grafana.com/oss/deb stable main" | sudo tee /etc/apt/sources.list.d/grafana.list
sudo apt-get update
sudo apt-get install grafana -y
# Start Grafana
sudo systemctl start grafana-server
sudo systemctl enable grafana-serverAdd Prometheus as a Data Source:
- Open Grafana at
http://YOUR_IP:3000(default: admin/admin) - Go to Configuration → Data Sources → Add data source
- Select Prometheus
- Set URL to
http://localhost:9090 - Click Save & Test
📊 Recommended Dashboards:
- • Node Exporter Full (ID: 1860) - Server metrics
- • Docker Dashboard (ID: 893) - Container monitoring
- • MySQL Overview (ID: 7362) - Database metrics
Maintenance & Useful Queries
Storage Management
# Check Prometheus storage usage
du -sh /var/lib/prometheus/
# Create snapshot via API
curl -X POST http://localhost:9090/api/v1/admin/tsdb/snapshot
# Copy to backup location
cp -r /var/lib/prometheus/snapshots/* /backup/prometheus/Useful PromQL Queries
# CPU usage percentage
100 - (avg by(instance) (rate(node_cpu_seconds_total{mode="idle"}[5m])) * 100)
# Memory usage percentage
(1 - (node_memory_MemAvailable_bytes / node_memory_MemTotal_bytes)) * 100
# Disk usage percentage
(1 - (node_filesystem_avail_bytes{mountpoint="/"} / node_filesystem_size_bytes{mountpoint="/"})) * 100
# Network traffic (bytes/sec)
rate(node_network_receive_bytes_total[5m])Troubleshooting
Prometheus won't start
# Check logs
sudo journalctl -u prometheus -f
# Validate configuration
promtool check config /etc/prometheus/prometheus.yml
# Check file permissions
ls -la /etc/prometheus/
ls -la /var/lib/prometheus/Target shows as DOWN
# Check if exporter is running
curl localhost:9100/metrics
# Check firewall rules
sudo ufw status
# Test connectivity from Prometheus server
curl http://target_ip:9100/metricsReload without restart
# Send SIGHUP signal
sudo kill -HUP $(pidof prometheus)
# Or use the reload endpoint
curl -X POST http://localhost:9090/-/reloadCongratulations!
You've successfully deployed Prometheus monitoring on your RamNode VPS. Your metrics collection system is now operational.
Security Considerations
- • Never expose Prometheus directly to the internet - Always use a reverse proxy with authentication
- • Use firewall rules - Restrict port 9090 and 9100 to trusted IPs only
- • Enable HTTPS - Use SSL certificates for all external access
- • Secure Node Exporters - Use basic auth or keep them on private networks
- • Regular updates - Keep Prometheus and exporters updated for security patches
