Skip to content

[๐Ÿ‹] Exports Docker container metrics to Prometheus. Supports Docker, Swarm, and Rancher envs with cgroups v1/v2.

Notifications You must be signed in to change notification settings

shinbatsu/prometheus-docker-integration

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

24 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

Docker metrics in Prometheus

Export Docker container metrics (memory usage, limits, and reservations) to Prometheus.

Features

  • Collcts memory metrics per container.
  • Supports Docker Swarm, Rancher, and Compose labels for stack/service identification.
  • Compatible with cgroups v1 and v2.
  • Exposes /metrics endpoint for Prometheus scraping.

Usage

Running via Docker

You can run the exporter as a Docker container. Example:

services:
  prometheus-integration:
    image: <your-docker-username>/prometheus-integration:latest
    privileged: true
    environment:
      DOCKER_CLUSTER_CGROUP_VERSION: v2
    network_mode: host
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock:ro
      - /sys:/host:ro
    pid: host
    ports:
      - "9476:9476"
  • The exporter reads container cgroups from /host/sys.
  • If you use cgroups v2, use DOCKER_CLUSTER_CGROUP_VERSION=v2.
  • The /var/run/docker.sock volume allows the exporter to request Docker container info.

Running Locally

  1. Build binary with Go 1.21:
go build -o prometheus-integration main.go
  1. Run exporter:
./prometheus-integration
  1. Metrics are available at http://localhost:9476/metrics.

Running via Docker Compose

version: '3.9'
services:
  prometheus-integration:
    build: .
    container_name: prometheus-docker-integration
    privileged: true
    pid: host
    network_mode: host
    environment:
      DOCKER_CLUSTER_CGROUP_VERSION: v2
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock:ro
      - /sys:/host:ro
    ports:
      - "9476:9476"
    restart: unless-stopped

Metrics

Metric Description
docker_container_memory_usage_bytes Memory usage of container in bytes (excluding cache)
docker_container_memory_reservation_bytes Memory reserved for container
docker_container_memory_limit_bytes Memory limit for container

Env Variables

  • DOCKER_CLUSTER_CGROUP_VERSION โ€“ Optional, v1 (default) or v2.

About

[๐Ÿ‹] Exports Docker container metrics to Prometheus. Supports Docker, Swarm, and Rancher envs with cgroups v1/v2.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages