Skip to content

fendi-321/prometheus-lab

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Prometheus & Grafana Monitoring Stack

A complete monitoring and observability solution using Prometheus, Grafana, and Blackbox Exporter to track the uptime, performance, and SSL health of www.maffindi.com and www.maffindi.my.


Architecture

                         +-------------------+
                         |   www.maffindi.com |
                         |   www.maffindi.my  |
                         +---------+---------+
                                   |
                           HTTP/HTTPS probes
                                   |
                         +---------+---------+
                         | Blackbox Exporter  |
                         |  (prom/blackbox-   |
                         |   exporter:latest) |
                         +---------+---------+
                                   |
                            metrics (port 9115)
                                   |
                         +---------+---------+
                         |     Prometheus     |
                         |  (prom/prometheus  |
                         |   :latest)         |
                         +---------+---------+
                                   |
                            data source query
                                   |
                         +---------+---------+
                         |      Grafana      |
                         |  (grafana/grafana |
                         |   :latest)        |
                         +-------------------+

How It Works

Component Role
Blackbox Exporter Acts as a probing agent. It sends HTTP/HTTPS requests to each configured target (maffindi.com & maffindi.my) and exposes the results as Prometheus metrics.
Prometheus The heart of the stack. It scrapes the Blackbox Exporter every 15 seconds, stores all metrics in a time-series database, and provides a powerful query language (PromQL) to analyze the data.
Grafana The visualization layer. It connects to Prometheus as a data source and renders dashboards with charts, graphs, and status panels for real-time monitoring.

What We Monitor

1. Website Availability (Uptime)

  • Metric: probe_success
  • Values: 1 = site is up and responding, 0 = site is down
  • Granularity: Checked every 15 seconds

2. HTTP Response Time (Latency)

  • Metric: probe_http_duration_seconds
  • Phases measured:
    • resolve — DNS lookup time
    • connect — TCP connection time
    • tls — TLS handshake time
    • transfer — Time to receive response

3. SSL/TLS Certificate Health

  • Metric: probe_ssl_earliest_cert_expiry
  • What it tracks: When the SSL certificate expires (Unix timestamp)
  • Alert use case: Warn when cert expires within 30 days

4. HTTP Status Codes

  • Metric: probe_http_status_code
  • Expected: 200 (OK)
  • Monitors: Any unexpected codes (404, 500, 502, 301 redirects, etc.)

Services

Service URL Access Credentials
Prometheus http://localhost:9090 Open (no auth)
Grafana http://localhost:3000 Login required Username: admin, Password: admin
Blackbox Exporter Internal only (Docker network) Not exposed externally

Quick Start

# Clone the repository
git clone git@github.com:fendi-321/prometheus-lab.git
cd prometheus-lab

# Start all services
docker compose up -d

# Verify everything is running
docker compose ps

Grafana Dashboard

Import a Pre-Made Dashboard

  1. Login at http://localhost:3000 (admin / admin)
  2. Click DashboardsNewImport
  3. Enter ID: 7587 (Blackbox Exporter Dashboard)
  4. Select Prometheus as the data source
  5. Click Import

Useful PromQL Queries

Query Purpose
probe_success{instance="https://www.maffindi.com"} Uptime for maffindi.com
probe_success{instance="https://www.maffindi.my"} Uptime for maffindi.my
probe_http_duration_seconds{phase="connect"} TCP connection latency
probe_http_duration_seconds{phase="tls"} TLS handshake latency
(probe_ssl_earliest_cert_expiry - time()) / 86400 Days until SSL cert expires
probe_http_status_code HTTP status codes returned

Project Structure

prometheus-lab/
├── docker-compose.yml                 # Orchestrates all services
├── prometheus/
│   └── prometheus.yml                 # Prometheus scrape configuration
├── blackbox-exporter/
│   └── blackbox.yml                   # Blackbox probe module definitions
├── grafana/
│   ├── datasources/
│   │   └── datasource.yml             # Auto-provisions Prometheus data source
│   └── dashboards/
│       └── dashboards.yml             # Dashboard provisioning config
├── .gitignore
└── README.md

Customization

Adding More Websites

Edit prometheus/prometheus.yml and add targets under the blackbox-http job:

static_configs:
  - targets:
    - https://www.maffindi.com
    - https://www.maffindi.my
    - https://your-new-site.com

Then restart Prometheus:

docker compose restart prometheus

Changing Scrape Interval

Edit the scrape_interval in prometheus/prometheus.yml (default: 15s).


Useful Commands

# View container status
docker compose ps

# View live logs
docker compose logs -f

# Stop all services
docker compose down

# Restart a specific service
docker compose restart prometheus
docker compose restart grafana
docker compose restart blackbox-exporter

Muhamad Affindi

About

prometheus lab

Resources

Stars

2 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors