
Prometheus is an open-source monitoring and alerting toolkit designed for reliability and scalability. It collects and stores metrics as time-series data with timestamps and optional labels, enabling powerful querying and analysis of your infrastructure and applications.
In this article, you will deploy Prometheus using Docker Compose, configure persistent storage for metrics data, and set up Traefik as a reverse proxy to securely access your Prometheus instance.
Before you begin, you need to:
sudo privileges.prometheus.example.com).In this section, you prepare the required directory structure for Prometheus and define environment variables in a .env file.
Create the directory structure for Prometheus.
These directories serve different purposes:
Navigate into the prometheus-monitoring directory.
Set proper ownership for the Prometheus data directory. Prometheus runs as the nobody user (UID 65534) inside the container.
Create a .env file.
Add the following variables:
Replace:
prometheus.example.com with your domain.admin@example.com with your email.Save and close the file.
Create a Prometheus configuration file.
Add the following content.
Save and close the file.
The configuration includes:
/metrics endpoint.In this section, you create and deploy the Docker Compose stack that runs Prometheus behind Traefik. Docker Compose manages both containers, applies the environment variables from your .env file, and automatically configures HTTPS routing through Traefik.
Create a new Docker Compose manifest.
Add the following content.
Save and close the file.
This configuration defines:
./prometheus-config, ./prometheus-data) ensure configuration files and metric databases survive container recreation.letsencrypt named volume retains TLS certificate data between container lifecycles./var/run/docker.sock grants Traefik read-only access to the Docker daemon for service discovery.Create and start the services.
Verify that the services are running.
Output:
Both containers are running as expected. Prometheus collects metrics while Traefik accepts connections on ports 80 and 443.
View the logs of the services.
For more information on managing a Docker Compose stack, see the How To Use Docker Compose article.
In this section, you access the Prometheus web interface and verify your monitoring setup by running basic queries to explore collected metrics.
Open the Prometheus web interface in your browser.
Click Status > Target health to view monitored endpoints. You should see the prometheus job with a state of UP.
Navigate to the Query tab to explore metrics using PromQL.
Try these example queries:
Check target scrape status:
View CPU usage:
View memory usage:
Click Execute after entering each query to see the results. Switch to the Graph tab to visualize metrics over time.
You have successfully deployed Prometheus for system monitoring with encrypted HTTPS connectivity. The Docker Compose deployment includes both the Prometheus metrics engine and Traefik reverse proxy, with durable storage ensuring data retention across restarts. Let's Encrypt certificate automation provides secure connections while Traefik handles intelligent request routing. Your monitoring infrastructure is ready for expansion through additional exporters, custom application instrumentation, and alerting rules.
0 Comments
Be the first to comment and share your perspective with the community.