Executive Summary
In today’s digital-first world, ensuring that your website and APIs are available and performing well is critical. A few minutes of downtime can result in lost customers, revenue, and trust. This blog explains how to set up Prometheus, Blackbox Exporter, and Grafana on an AWS EC2 instance to continuously monitor website uptime, SSL certificate validity, and response times with visual dashboards and alerts.
Problem
Businesses often face challenges in knowing when their websites or applications go down. Traditional monitoring tools can be expensive or complex to set up, leaving gaps in visibility. Without proper monitoring:
-
Downtime may go unnoticed until reported by users.
-
SSL certificates can expire unexpectedly.
-
Page load delays or DNS failures remain undetected.
The need for a reliable, open-source, and cost-effective solution to track website availability and performance metrics is clear.
Solution
By combining Prometheus for time-series data collection, Blackbox Exporter for probing website endpoints, and Grafana for visualization, you can build a robust monitoring solution that:
-
Continuously checks website uptime and response codes.
-
Monitors SSL expiry to prevent unexpected downtime.
-
Tracks latency, DNS resolution, and HTTP response times.
-
Provides real-time dashboards and alerting capabilities.
This solution is deployed on a Linux-based Ec2 instance and uses entirely open-source tools.
Prerequisites
Before starting, ensure you have the following:
-
An AWS EC2 instance (Ubuntu or Amazon Linux 2) with at least 2 GB RAM.
-
A domain or set of URLs you want to monitor.
-
Access to the EC2 instance via SSH.
-
Basic knowledge of Linux commands.
-
Ports 9090 (Prometheus), 9115 (Blackbox Exporter), and 3000 (Grafana) allowed in the EC2 Security Group.
Challenges
While implementing, you may encounter:
-
Firewall and Security Group restrictions preventing access to Grafana or Prometheus.
-
Incorrect scrape configurations in Prometheus resulting in no metrics collected.
-
CORS or SSL certificate errors when probing HTTPS websites.
-
Grafana authentication and datasource setup issues if not properly configured.
Scenario
Consider a financial services company that needs to ensure its customer-facing portal and API endpoints are always online. Using Prometheus and Blackbox Exporter, they want to:
-
Monitor their website URLs.
-
Receive early warnings if the SSL certificate is nearing expiry.
-
Visualize uptime history and response times in Grafana dashboards.
Step-by-Step Solution
1. Install Prometheus
Comments:
sudo useradd –no-create-home –shell /bin/false prometheus
sudo mkdir /etc/prometheus /var/lib/prometheus
sudo apt update && sudo apt install wget tar -y
cd /tmp
wget https://github.com/prometheus/prometheus/releases/download/v2.53.0/prometheus-2.53.0.linux-amd64.tar.gz
tar -xvf prometheus-2.53.0.linux-amd64.tar.gz
cd prometheus-2.53.0.linux-amd64/
sudo cp prometheus promtool /usr/local/bin/
sudo cp -r consoles console_libraries /etc/prometheus/
sudo cp prometheus.yml /etc/prometheus/prometheus.yml
sudo chown -R prometheus:prometheus /etc/prometheus /var/lib/prometheus
Create Prometheus service:
[Unit]
Description=Prometheus
Wants=network-online.target
After=network-online.target
[Service]
User=prometheus
ExecStart=/usr/local/bin/prometheus \
–config.file=/etc/prometheus/prometheus.yml \
–storage.tsdb.path=/var/lib/prometheus \
–web.listen-address=:9090 \
–web.enable-lifecycle
[Install]
WantedBy=multi-user.target
Enable and start:
sudo systemctl daemon-reexec
sudo systemctl enable prometheus
sudo systemctl start prometheus
2. Install Blackbox Exporter
cd /tmp
wget https://github.com/prometheus/blackbox_exporter/releases/download/v0.25.0/blackbox_exporter-0.25.0.linux-amd64.tar.gz
tar -xvf blackbox_exporter-0.25.0.linux-amd64.tar.gz
cd blackbox_exporter-0.25.0.linux-amd64/
sudo cp blackbox_exporter /usr/local/bin/
sudo mkdir /etc/blackbox_exporter
sudo cp blackbox.yml /etc/blackbox_exporter/
Create Blackbox service:
[Unit]
Description=Blackbox Exporter
After=network.target
[Service]
ExecStart=/usr/local/bin/blackbox_exporter \
–config.file=/etc/blackbox_exporter/blackbox.yml
Restart=always
[Install]
WantedBy=multi-user.target
Enable and start:
sudo systemctl daemon-reexec
sudo systemctl enable blackbox_exporter
sudo systemctl start blackbox_exporter
3. Configure Prometheus to Use Blackbox Exporter
Edit /etc/prometheus/prometheus.yml
:
scrape_configs:
– job_name: ‘blackbox’
metrics_path: /probe
params:
module: [http_2xx]
static_configs:
– targets:
– https://example.com
– https://google.com
relabel_configs:
– source_labels: [__address__]
target_label: __param_target
– source_labels: [__param_target]
target_label: instance
– target_label: __address__
replacement: localhost:9115
Restart Prometheus:
sudo systemctl restart prometheus
4. Install Grafana
sudo apt-get install -y apt-transport-https software-properties-common
wget -q -O – https://packages.grafana.com/gpg.key | sudo apt-key add –
sudo add-apt-repository “deb https://packages.grafana.com/oss/deb stable main”
sudo apt-get update
sudo apt-get install grafana -y
sudo systemctl enable grafana-server
sudo systemctl start grafana-server
Access Grafana:
http://<EC2_PUBLIC_IP>:3000
(Default login: admin / admin)
5. Add Prometheus Datasource in Grafana
-
Go to Configuration → Data sources → Add data source
-
Select Prometheus
-
URL:
http://localhost:9090
-
Save & Test
6. Import a Ready-made Blackbox Dashboard
-
Go to Dashboards → Import
-
Enter Dashboard ID: 7587
-
Select your Prometheus datasource
-
Click Import
You’ll now see uptime metrics including:
-
Status (UP/DOWN)
-
HTTP status code
-
SSL expiry
-
Response time and latency
Conclusion
With this setup, you now have a complete uptime monitoring solution using Prometheus, Blackbox Exporter, and Grafana on AWS EC2. This ensures you’re always aware of your website’s availability, SSL health, and performance without relying on expensive commercial tools.