Deploying Prometheus for Linux System Monitoring: A Practical Docker-Based Guide
Set Up Node Exporter for Linux System Metrics
Pull the Node Exporter Docker image to collect Linux system resource metrics:
docker pull prom/node-exporter
Start the Node Exporter container, exposing port 9100 (the default port for metric collection):
docker run -d \
--name linux-metrics-exporter \
-p 9100:9100 \
--net="host" \
prom/node-exporter
Verify the container is operational using docker ps or check the listening port with ss -tulpn | grep 9100. Ensure port 9100 is open in your server's firewall or security group. You can validate metric availability by running curl http://<your-server-ip>:9100/metrics or visiting the URL in a browser.
Deploy and Configure Prometheus
Pull Prometheus Image
Retrieve the official Prometheus Docker image:
docker pull prom/prometheus
Create Configuration Directory and File
Set up a dedicated directory for Prometheus configuration files:
mkdir -p /opt/prometheus/config && cd /opt/prometheus/config
Create a prometheus.yml configuration file with the following content using vim prometheus.yml:
global:
scrape_interval: 30s
evaluation_interval: 30s
scrape_configs:
- job_name: 'prometheus_self_monitor'
static_configs:
- targets: ['localhost:9090']
- job_name: 'linux_infrastructure'
static_configs:
- targets: ['<your-server-ip>:9100']
Launch Prometheus Container
Start the Prometheus container, mounting the custom configuration file:
docker run -d \
--name prometheus-server \
-p 9090:9090 \
-v /opt/prometheus/config/prometheus.yml:/etc/prometheus/prometheus.yml \
prom/prometheus
Confirm the container is running with docker ps or check port 9090 with ss -tulpn | grep 9090. Access the Prometheus UI at http://<your-server-ip>:9090 to review the service status. Navigate to http://<your-server-ip>:9090/targets to ensure both scrape jobs are marked as "UP".
Set Up Grafana for Visualization
Pull the specified Grafana version image:
docker pull grafana/grafana:7.5.16
Start the Grafana container:
docker run -d \
--name grafana-dashboard \
-p 3000:3000 \
grafana/grafana:7.5.16
Accesss the Grafana UI at http://<your-server-ip>:3000 using default credentials (admin/admin, which you’ll be prompted to change on firrst login).
Add Prometheus as a Data Source
- Navigate to Connections > Data Sources from the sidebar and click Add data source.
- Select Prometheus from the list of available sources.
- Enter you're Prometheus server URL (e.g.,
http://<your-server-ip>:9090) and click Save & Test to confirm connectivity.
Import Pre-Built Monitoring Dashboard
- Go to Dashboards > New > Import from the sidebar.
- Input dashboard ID
12633and click Load. - Select the Prometheus data source you added, then click Import.
- Customize the dashboard name or settings as needed; the imported dashboard will display real-time Linux system metrics collected via Node Exporter and Prometheus.