Skip to content

Repository files navigation

logporter

Docker Hub Pulls
Docker Image Size

A simple and lightweight alternative to cAdvisor for extracting basic and custom metrics from Docker containers.

The exporter supports a metric displaying the number of logs over the scrape period. With proper logging configuration and stream separation on the application side, this metric can reflect the actual traffic volume and error rate.

Comparative measurement of CPU and memory usage from cAdvisor and logporter metrics in 3 hours:

Note

On average, CPU consumption is 15-20 times lower and memory consumption is 10 times lower in the basic metrics mode (including IOps and uptime) compared to cAdvisor.

Quick start

Clone the repository and run the pre-configured monitoring stack with a single command:

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

The dashboard and Prometheus data source with the added exporter are already connected to Grafana.

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

Manual configuration

  • Build the Docker image yourself (optional):
docker build -t lifailon/logporter .
  • Run the exporter in a container using a locally built image or one published on Docker Hub:
docker run -d --name logporter \
  -v /var/run/docker.sock:/var/run/docker.sock \
  -p 9333:9333 \
  --restart=always \
  lifailon/logporter:latest

Or use compose to securely use 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
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock:ro

Use environment variables to configure the exporter:

Label Type Default Description
DOCKER_METRICS_PORT int 9333 The port on which the exporter is listening.
DOCKER_METRICS_HOSTNAME string "" A custom hostname that appears in metric tags.
DOCKER_METRICS_CACHE int 15 Cache time for all collected metrics in seconds.
DOCKER_METRICS_LOG boolean false Collecting the number of messages in logs from all streams.
DOCKER_METRICS_LOG_CACHE int 15 Cache time for collected logs metrics in seconds.
DOCKER_METRICS_VOLUME boolean true Collecting a list of all volumes and their sizes.
DOCKER_METRICS_VOLUME_CACHE int 30 Cache time for collected volumes metrics in minutes.
DOCKER_HOST string "" Optional: use a docker proxy instead of the docker socket mount for additional security.

Warning

Using custom metrics may increase resource consumption (depending on the number of containers and the logs they contain). The metrics themselves are transmitted instantly thanks to data collection by background workers and caching. Check the duration value in the exporter logs to ensure that it does not exceed the scrape interval.

  • 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

List of metrics

Name Data type Help description
docker_image_size gauge The size of the image minus the layer shared by other images
docker_volume_size gauge The size of the volumes and the number of containers associated with it in the volumeUsage tag
docker_container_status gauge Container status: running (1) or stopped (0)
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_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
docker_logs_stdout_count counter Number of messages in logs from standard output
docker_logs_stderr_count counter Number of messages in logs from error output
docker_started_time gauge Container started time

About

A simple and lightweight alternative to cAdvisor for getting all basic metrics from Docker containers with support metrics by logs.

Topics

Resources

Stars

50 stars

Watchers

0 watching

Forks

Releases

Contributors

Languages