Back to articles
DevOps & Systems

Detailed Guide to Setting Up Distributed Monitoring with Grafana Alloy and Prometheus on VPS

A detailed guide to setting up a distributed monitoring system using Grafana Alloy and Prometheus on a VPS, covering installation, configuration, and operational verification.

DPTCloud Engineering4 min read
Detailed Guide to Setting Up Distributed Monitoring with Grafana Alloy and Prometheus on VPS

Image credit: TerriC · Pixabay Content License

Introduction to Distributed Monitoring Systems

Distributed monitoring systems are essential in modern DevOps environments, especially when managing multiple servers or services on VPS platforms. As microservices architectures grow in complexity, tracking performance, status, and errors across individual components becomes increasingly challenging. Grafana Alloy and Prometheus are powerful tools that enable the creation of effective, flexible, and scalable monitoring systems.

Grafana Alloy is a new tool from Grafana Labs that integrates data collection, processing, and export into Grafana, replacing older tools like Prometheus Pushgateway or Logstash. Prometheus is an open-source monitoring and alerting toolkit known for its ability to collect data from endpoints and store time-series data efficiently.

This guide will walk you through setting up a distributed monitoring system using Grafana Alloy and Prometheus on a VPS. It covers installation, configuration, and operational verification steps.

Requirements and Prerequisites

To complete this guide, you will need:

  • A VPS server (use NVMe Cloud VPS for high performance).
  • SSH access to the VPS with root or sudo privileges.
  • Docker and Docker Compose installed (if needed).
  • Firewall ports 9090 (Prometheus), 3100 (Alloy), and 3000 (Grafana) opened.

Setting Up Grafana Alloy and Prometheus on VPS

We will use Docker to deploy Grafana Alloy and Prometheus. First, create a new directory to store configuration and data:

mkdir -p /opt/grafana-monitoring
cd /opt/grafana-monitoring

Create a docker-compose.yml file to define the services:

version: '3.8'

services:
  prometheus:
    image: prom/prometheus:latest
    container_name: prometheus
    volumes:
      - ./prometheus.yml:/etc/prometheus/prometheus.yml
    ports:
      - "9090:9090"
    command:
      - --config.file=/etc/prometheus/prometheus.yml
      - --storage.tsdb.path=/prometheus
      - --web.console.templates=/etc/prometheus/consoles
      - --web.console.libraries=/etc/prometheus/console_libraries
    restart: unless-stopped

  grafana-alloy:
    image: grafana/alloy:latest
    container_name: grafana-alloy
    volumes:
      - ./alloy.yaml:/etc/alloy/alloy.yaml
    ports:
      - "3100:3100"
    command:
      - --config.file=/etc/alloy/alloy.yaml
    restart: unless-stopped

  grafana:
    image: grafana/grafana:latest
    container_name: grafana
    ports:
      - "3000:3000"
    volumes:
      - ./grafana-data:/var/lib/grafana
    environment:
      - GF_SECURITY_ADMIN_USER=admin
      - GF_SECURITY_ADMIN_PASSWORD=admin
    restart: unless-stopped

Create a prometheus.yml configuration file:

global:
  scrape_interval: 15s

scrape_configs:
  - job_name: 'prometheus'
    static_configs:
      - targets: ['localhost:9090']
  - job_name: 'alloy'
    static_configs:
      - targets: ['localhost:3100']

Create an alloy.yaml configuration file:

prometheus.scrape "localhost" {
  targets = ["localhost:9090"]
  forward_to = [prometheus.remote_write.receiver]
}

prometheus.remote_write "grafana_cloud" {
  endpoint {
    url = "https://prometheus.grafana.net/api/prom/push"
  }
  basic_auth {
    username = "YOUR_USERNAME"
    password = "YOUR_PASSWORD"
  }
}

Replace YOUR_USERNAME and YOUR_PASSWORD with your Grafana Cloud credentials if sending data to Grafana Cloud.

Verification and Operational Testing

Start the services using Docker Compose:

docker-compose up -d

Check the status of the containers:

docker-compose ps

Ensure all containers are running. Verify Prometheus at http://your-vps-ip:9090 and Grafana at http://your-vps-ip:3000.

Log in to Grafana using admin/admin and add Prometheus as a data source.

Troubleshooting

  • If Prometheus fails to collect data, verify the prometheus.yml configuration.
  • If Alloy fails to send data, check connectivity to Grafana Cloud and authentication details.
  • If Grafana does not display data, confirm the connection to Prometheus and data source configuration.

References

Related infrastructure & engineering guides: Configure Cilium CNI with eBPF for High Network Performance in VPS Micro Cluster

DPTCloud Tier III Infrastructure

Recommended NVMe Cloud VPS Plans to Deploy This Setup

Enterprise RAID 10 NVMe SSDs, CMC & FPT District 9 uplinks with Anycast Anti-DDoS and 99.99% SLA.

View 22 VPS Plans
ECO · vn-02

VPS-2E

94.600 ₫ / mo

10% VAT included

  • CPU: 2 vCPU
  • RAM: 2 GB
  • SSD: 30 GB NVMe
ECO · vn-02Recommended

VPS-3E

170.500 ₫ / mo

10% VAT included

  • CPU: 2 vCPU
  • RAM: 4 GB
  • SSD: 50 GB NVMe
BASIC · vn-01Recommended

VPS-05

457.600 ₫ / mo

10% VAT included

  • CPU: 4 vCPU
  • RAM: 8 GB
  • SSD: 50 GB NVMe

Related Articles

View all
ZaloZalo SupportDiscord0384 753 478