Fading Coder

One Final Commit for the Last Sprint

Home > Tech > Content

Deploying Prometheus for Linux System Monitoring: A Practical Docker-Based Guide

Tech 1

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

  1. Navigate to Connections > Data Sources from the sidebar and click Add data source.
  2. Select Prometheus from the list of available sources.
  3. 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

  1. Go to Dashboards > New > Import from the sidebar.
  2. Input dashboard ID 12633 and click Load.
  3. Select the Prometheus data source you added, then click Import.
  4. Customize the dashboard name or settings as needed; the imported dashboard will display real-time Linux system metrics collected via Node Exporter and Prometheus.

Related Articles

Understanding Strong and Weak References in Java

Strong References Strong reference are the most prevalent type of object referencing in Java. When an object has a strong reference pointing to it, the garbage collector will not reclaim its memory. F...

Comprehensive Guide to SSTI Explained with Payload Bypass Techniques

Introduction Server-Side Template Injection (SSTI) is a vulnerability in web applications where user input is improper handled within the template engine and executed on the server. This exploit can r...

Implement Image Upload Functionality for Django Integrated TinyMCE Editor

Django’s Admin panel is highly user-friendly, and pairing it with TinyMCE, an effective rich text editor, simplifies content management significantly. Combining the two is particular useful for bloggi...

Leave a Comment

Anonymous

◎Feel free to join the discussion and share your thoughts.