What You’ll Need

  • A server or virtual machine to run Prometheus and Grafana (recommended: 2 GB RAM, 2 CPUs).
  • Docker installed (or native installation on Linux).
  • Basic understanding of system metrics and networking.

Step 1: Install Prometheus

  1. Create a Prometheus data directory:

    mkdir -p ~/prometheus/data
    
  2. Create a Prometheus configuration file:

    nano ~/prometheus/prometheus.yml
    

    Add the following content to scrape metrics from localhost:

    global:
      scrape_interval: 15s
    
    scrape_configs:
      - job_name: 'prometheus'
        static_configs:
          - targets: ['localhost:9090']
    
  3. Run Prometheus using Docker:

    docker run -d --name prometheus -p 9090:9090 \
      -v ~/prometheus/prometheus.yml:/etc/prometheus/prometheus.yml \
      -v ~/prometheus/data:/prometheus \
      prom/prometheus
    
  4. Access Prometheus:
    Open your browser and navigate to http://<server_ip>:9090.


Step 2: Install Grafana

  1. Run Grafana using Docker:

    docker run -d --name=grafana -p 3000:3000 grafana/grafana
    
  2. Access Grafana:
    Open your browser and navigate to http://<server_ip>:3000.

    • Default username: admin
    • Default password: admin
  3. Change the default password when prompted.


Step 3: Connect Prometheus to Grafana

  1. Add Prometheus as a data source:

    • In Grafana, go to Settings > Data Sources > Add Data Source.
    • Choose Prometheus from the list.
    • Set the URL to http://<server_ip>:9090.
  2. Click Save & Test to verify the connection.


Step 4: Create Dashboards

  1. Import a prebuilt dashboard:

    • Go to Create > Import in Grafana.
    • Use a popular dashboard ID from the Grafana Dashboard Library, like 1860 (Node Exporter Full).
  2. Customize your dashboard:

    • Add or remove panels based on the metrics you care about.

Step 5: Set Up Alerts in Grafana

  1. Create a new alert:

    • Open any panel in your dashboard.
    • Click on the bell icon and configure alert conditions.
  2. Set up notification channels:

    • Go to Alerting > Notification Channels in Grafana.
    • Add methods like email, Slack, or webhooks for alerts.

FAQs

Q: Can I run Prometheus and Grafana on the same server?
A: Yes, they are lightweight and can run together on a single machine.

Q: What kind of metrics can I monitor?
A: You can monitor system performance (CPU, memory, disk usage), network activity, application-specific metrics, and more.

Q: How do I secure Prometheus and Grafana?
A: Use reverse proxies like Nginx with HTTPS enabled and restrict access to trusted IPs.

Q: Can I add other data sources to Grafana?
A: Yes, Grafana supports multiple data sources, including InfluxDB, Elasticsearch, and MySQL.

Q: How do I persist Grafana data?
A: Use Docker volumes to store Grafana data, like:
bash docker run -d --name=grafana -p 3000:3000 \ -v ~/grafana/data:/var/lib/grafana \ grafana/grafana

Q: Can I set up notifications without Grafana?
A: Yes, Prometheus supports its own alerting rules and integrates with Alertmanager for notifications.

Q: How do I scale Prometheus?
A: Use Prometheus federation or set up a Thanos instance for scalable storage and querying.


By deploying Prometheus and Grafana, you can keep a close eye on your homelab’s performance and ensure everything runs smoothly. Happy monitoring!