Blackbox exporter icmp

From UVOO Tech Wiki
Jump to navigation Jump to search

Dockerfile

# Use a lightweight base image
FROM alpine:latest

# Install necessary packages
RUN apk add --no-cache \
    libcap \
    curl

# Download and install Blackbox Exporter
ENV BLACKBOX_EXPORTER_VERSION 0.23.0
RUN wget https://github.com/prometheus/blackbox_exporter/releases/download/v${BLACKBOX_EXPORTER_VERSION}/blackbox_exporter-${BLACKBOX_EXPORTER_VERSION}.linux-amd64.tar.gz && \
    tar -xzf blackbox_exporter-${BLACKBOX_EXPORTER_VERSION}.linux-amd64.tar.gz && \
    mv blackbox_exporter-${BLACKBOX_EXPORTER_VERSION}.linux-amd64/blackbox_exporter /usr/local/bin/blackbox_exporter && \
    rm -rf blackbox_exporter-${BLACKBOX_EXPORTER_VERSION}.linux-amd64*

# Set the capability to allow ICMP
RUN setcap cap_net_raw+ep /usr/local/bin/blackbox_exporter

# Create a user with UID 1000
RUN adduser -D -u 1000 nonrootuser

# Create a configuration file for Blackbox Exporter
COPY blackbox.yml /etc/blackbox_exporter/config.yml

# Set the permissions
RUN chown nonrootuser:nonrootuser /etc/blackbox_exporter/config.yml

# Expose the port
EXPOSE 9115

# Run the exporter as the non-root user
USER nonrootuser

# Command to run the Blackbox Exporter
CMD ["blackbox_exporter", "--config.file=/etc/blackbox_exporter/config.yml"]

More steps

Step 2: Create a Configuration File
Create a blackbox.yml configuration file in the same directory as your Dockerfile.

yaml
Copy code
modules:
  icmp:
    prober: icmp
    timeout: 5s
Step 3: Build the Docker Image
Build the Docker image using the Dockerfile.

sh
Copy code
docker build -t blackbox-exporter-icmp .
Step 4: Run the Docker Container
Run the container with the appropriate user and expose the port.

sh
Copy code
docker run -d -p 9115:9115 --name blackbox-exporter-icmp blackbox-exporter-icmp
Step 5: Verify the Setup
Check the Blackbox Exporter:

Verify that the Blackbox Exporter is running and capable of performing ICMP probes by visiting the probe endpoint in your browser or using curl.

sh
Copy code
curl "http://localhost:9115/probe?target=example.com&module=icmp"
Configure Prometheus:

Add a scrape configuration in your prometheus.yml to scrape the Blackbox Exporter.

yaml
Copy code
scrape_configs:
  - job_name: 'blackbox'
    metrics_path: /probe
    params:
      module: [icmp]
    static_configs:
      - targets:
        - example.com
    relabel_configs:
      - source_labels: [__address__]
        target_label: __param_target
      - source_labels: [__param_target]
        target_label: instance
      - target_label: __address__
        replacement: blackbox-exporter-icmp:9115
Reload Prometheus: