Skip to content

Repository files navigation

Docker Hub Pulls
Docker Image Size

A lightweight alternative to 🦉 cAdvisor for exporting metrics from Docker containers, a log collector for sending to Lok, and searching for new image versions in remote registries based on semantic analysis of tags or digests in a single container.

Performance

Comparative CPU and memory usage measurements using logporter with log collection enabled (left) and cAdvisor in a default configuration (right) over 24 hour for 25 containers:

The logporter exporter does not use low-level filesystem calls, but collects all metrics directly from the Docker socket.

Quick start

Clone the repository and run the monitoring full-stack with one command:

git clone https://github.com/Lifailon/logporter
cd logporter
docker-compose up -d --pull always

The stack includes Prometheus with an exporter connected and alerts configured, a Loki server targeted by a log collector, and Grafana with pre-configured data sources and added dashboards.

Go to Grafana UI: http://localhost:3000 and enter admin:admin.

Dashboard

The project supports a built-in dashboard that contains summary information on the status of all containers, images, and volumes. The interface is based on go-template and does not affect performance in any way, as it uses cached data.

Go to Dashboard: http://localhost:9333.

The dashboard allows you to view container logs in real time, with support for content filtering.

Manual setup

Exporter

  • Run the exporter in a container using the image published on Docker Hub:
docker run -d --name logporter \
  -v /var/run/docker.sock:/var/run/docker.sock:ro \
  -p 9333:9333 \
  --restart=always \
  lifailon/logporter:latest

All metrics are retrieved directly from the Docker socket, which requires read-only access (:ro).

Or use compose to fine-tune access to the Docker socket through a proxy:

services:
  logporter:
    image: lifailon/logporter:latest
    container_name: logporter
    restart: always
    ports:
      - 9333:9333
    environment:
      - DOCKER_HOST=tcp://docker-proxy:2375

  docker-proxy:
    image: lscr.io/linuxserver/socket-proxy:latest
    container_name: docker-proxy
    restart: always
    environment:
      - CONTAINERS=1
      - INFO=1
      - SYSTEM=1
      - IMAGES=1
      - DISTRIBUTION=1
      - ALLOW_LOGS=1
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock:ro

List of environment variables to configure:

Label Type Default Description
LOG_LEVEL string info Use debug to get detailed output of the exporter operation or error to suppress the output of info messages
DOCKER_METRICS_HOST string "" Host/IP address on which the HTTP server listens (default is all interfaces 0.0.0.0; set e.g. 127.0.0.1 when running standalone binary outside Docker)
DOCKER_METRICS_PORT int 9333 The port on which the exporter is listening
DOCKER_METRICS_HOSTNAME string "" Custom hostname displayed in Prometheus and Loki labels (by default from Docker API or OS)
DOCKER_METRICS_CUSTOM_LABELS string "" List of custom labels that will be added to all container metrics (only if present, e.g. org.opencontainers.image.version)
DOCKER_METRICS_CACHE int 15 Cache time for all collected metrics in seconds. Until the cache expires, queried metrics will return the last value received
DOCKER_METRICS_VOLUME boolean true Enable metrics collection for all volumes and their size. Data collection occurs in the background, without waiting for scrape
DOCKER_METRICS_VOLUME_CACHE int 30 Cache time for collected volumes metrics in minutes.
DOCKER_METRICS_IMAGE_UPDATE boolean true Enable digest-based update check metric
DOCKER_METRICS_IMAGE_INTERVAL int 30 Image update check interval in minutes
DOCKER_HOST string "" Change the socket address to monitor a remote host or proxy instead of mounting a Docker socket for increased security (optional)
  • Connect the new target to the Prometheus configuration file:
scrape_configs:
  - job_name: logporter
    scrape_interval: 15s
    scrape_timeout: 2s
    static_configs:
      - targets:
        - localhost:9333

Loki

  • Configure a connection with Loki to send logs using environment variables:
Label Type Default Description
LOKI_URL string "" Loki server address and port
LOKI_USERNAME string "" basic auth username for Loki (optional)
LOKI_PASSWORD string "" basic auth password for Loki (optional)
LOKI_TENANT_ID string "" Tenant id sent in the X-Scope-OrgID header (optional)
LOKI_PUSH_SECONDS int 5 Maximum wait time in seconds before pushing the batch to Loki
LOKI_PUSH_LINES int 1000 Maximum number of log entries (lines) before pushing the batch in one request
LOKI_BUFFER_LINES int 10000 Buffer size in entries before they are dropped (memory protection)

By default, metrics collection is disabled if the LOKI_URL variable is empty.

  • Import the prepared Loki log dashboard into Grafana from json file.

List of metrics

Name Data type Help description
docker_image_count gauge Number of images
docker_image_size gauge The size of the image minus the layer shared by other images
docker_image_update gauge Image update status based on digests: update required (1) or latest version (0)
docker_volume_size gauge The size of the volumes and the number of containers associated with it in the volumeUsage tag
docker_container_running_count gauge Number of running containers
docker_container_stopped_count gauge Number of stopped containers
docker_container_status gauge Container status: running (1) or stopped (0)
docker_container_healthy gauge Health check status
docker_started_time gauge Container started timestamp
docker_exit_code gauge Container exit code
docker_oom_killed gauge Memory limit exceeded
docker_size_rw gauge Size of the container writable layer in bytes
docker_size_root_fs gauge Total size of the container filesystem in bytes (shared image layers and writable layer)
docker_bind_mounts gauge Number of volumes mounted on host file system
docker_volume_mounts gauge Number of local volumes mounted
docker_cpu_total_number gauge Total available vCPUs
docker_cpu_usage_total counter Total CPU usage (user and kernel) in seconds
docker_cpu_usage_user counter User CPU usage in seconds
docker_cpu_usage_kernel counter Kernel CPU usage in seconds
docker_memory_total gauge Total memory size in bytes
docker_memory_current_limit gauge Current memory limit size in bytes (if no value is specified, the total amount of available memory is displayed)
docker_memory_inspect_limit gauge Memory limit size in bytes specified in the launch options (if the value is 0, then no limit is set)
docker_memory_usage gauge Usage memory size in bytes
docker_network_received_bytes counter Number of bytes received on the network
docker_network_received_packages counter Number of packages received on the network
docker_network_transmit_bytes counter Number of bytes transmitted on the network
docker_network_transmit_packages counter Number of packages transmitted on the network
docker_io_read_bytes counter Number of bytes read by the block device
docker_io_write_bytes counter Number of bytes write by the block device
docker_process_pids_count gauge Number of running processes and threads

List of available labels for container filtering:

Label Description
hostname Hostname obtained from the Docker API or custom from the DOCKER_METRICS_HOSTNAME variable
containerId Unique container identifier
containerName Container name from container_name in compose file
containerState The current status of the container (if the state is not running, then only inspect metrics are available)
composeProject Name of the compose project (usually the name of the directory where the compose file is located)
composeService Name of the service in the compose project (may differ from containerName)
composeWorkDir Path to the directory with the compose stack on the host

About

A lightweight alternative to cAdvisor for exporting metrics from Docker containers, a log collector for sending logs to Loki, a tool for finding new image versions, and a built-in Dashboard.

Topics

Resources

Stars

92 stars

Watchers

0 watching

Forks

Releases

Contributors

Languages