DEV Community

Muhammad Kamran Kabeer
Muhammad Kamran Kabeer

Posted on

How I Automated a Monitoring Stack on my Dell Latitude using Ansible & Docker

The Vision
As part of my Technical Lab Roadmap, I am moving away from manual configurations. In the world of modern DevOps, if you have to do it twice, you should automate it. Today’s goal: Transforming my Xubuntu-powered Dell Latitude into a fully monitored node using Infrastructure as Code (IaC).

The Architecture: A Three-Tier Observability Stack
To monitor a system effectively, you need a pipeline. Data must be generated, collected, and visualized. Here is how I structured this lab:

Generation (Node Exporter): A lightweight Go-based binary that exposes hardware metrics (CPU load, RAM usage, Disk I/O) via a web endpoint.

Collection (Prometheus): The "brain" of the operation. It's a time-series database that "scrapes" the metrics from the exporter at defined intervals.

Visualization (Grafana): The "eyes." It queries Prometheus to turn raw numbers into pulsing, real-time graphs.

The "Aha!" Moment: Solving Networking Hurdles
The biggest challenge was connectivity. When running Prometheus inside a Docker container, it views localhost as itself, not my laptop.

The Solution:

The Bridge: I used the Docker Gateway IP (172.17.0.1) to allow the container to look "outside" to the host hardware.

The Guard: Xubuntu’s UFW (Uncomplicated Firewall) initially blocked these requests. I had to explicitly allow traffic on port 9100 from the Docker interface.

The Implementation: Ansible Playbook
Instead of 20 terminal commands, I consolidated the entire setup into one Ansible Playbook. This ensures Idempotency—I can run this on any machine and get the exact same result.

YAML

  • name: Deploy Monitoring Stack hosts: localhost connection: local become: yes

tasks:
- name: Run Node Exporter (The Sensor)
community.docker.docker_container:
name: node-exporter
image: prom/node-exporter:latest
state: started
restart_policy: always
ports:
- "9100:9100"

- name: Run Prometheus (The Brain)
  community.docker.docker_container:
    name: prometheus
    image: prom/prometheus:latest
    state: started
    recreate: yes
    volumes:
      - "./prometheus.yml:/etc/prometheus/prometheus.yml"
      - "./alert_rules.yml:/etc/prometheus/alert_rules.yml"
    ports:
      - "9091:9090"

- name: Run Grafana (The Visuals)
  community.docker.docker_container:
    name: grafana
    image: grafana/grafana:latest
    state: started
    ports:
      - "3000:3000"
Enter fullscreen mode Exit fullscreen mode

Going Pro: Proactive Alerting
Monitoring is useless if you have to stare at the screen all day. I integrated Alertmanager with a custom rule:

If CPU usage exceeds 85% for more than 2 minutes, fire a CRITICAL alert.

This moves the lab from "Basic Monitoring" to "Incident Response Readiness."

Key Takeaways for Students & Peers
Infrastructure is Code: Never install manually what you can automate.

Firewalls Matter: If your data isn't flowing, check your UFW/Iptables first.

Start Small: I’m doing this on an 8GB RAM Dell laptop. You don't need a cloud budget to learn high-level DevOps.

Check out the full Source Code:
🔗 https://github.com/muhammadkamrankabeer-oss/Lab2_Monitoring_Automation

Top comments (0)