Sign inSign up

lifailon/logporter

By lifailon

Updated 3 days ago

A lightweight alternative to cAdvisor, log collector for sending to Lok, and searching for new image

Image
Integration & delivery
Developer tools
Monitoring & observability
1

100K+

lifailon/logporter repository overview

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.

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:

LabelTypeDefaultDescription
LOG_LEVELstringinfoUse debug to get detailed output of the exporter operation or error to suppress the output of info messages
DOCKER_METRICS_PORTint9333The port on which the exporter is listening
DOCKER_METRICS_HOSTNAMEstring""Custom hostname displayed in Prometheus and Loki labels (by default from Docker API or OS)
DOCKER_METRICS_CUSTOM_LABELSstring""List of custom labels that will be added to all container metrics (only if present, e.g. org.opencontainers.image.version)
DOCKER_METRICS_CACHEint15Cache time for all collected metrics in seconds. Until the cache expires, queried metrics will return the last value received
DOCKER_METRICS_VOLUMEbooleantrueEnable metrics collection for all volumes and their size. Data collection occurs in the background, without waiting for scrape
DOCKER_METRICS_VOLUME_CACHEint30Cache time for collected volumes metrics in minutes.
DOCKER_METRICS_IMAGE_UPDATEbooleantrueEnable digest-based update check metric
DOCKER_METRICS_IMAGE_INTERVALint30Image update check interval in minutes
DOCKER_HOSTstring""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:
LabelTypeDefaultDescription
LOKI_URLstring""Loki server address and port
LOKI_USERNAMEstring""basic auth username for Loki (optional)
LOKI_PASSWORDstring""basic auth password for Loki (optional)
LOKI_TENANT_IDstring""Tenant id sent in the X-Scope-OrgID header (optional)
LOKI_PUSH_SECONDSint5Maximum wait time in seconds before pushing the batch to Loki
LOKI_PUSH_LINESint1000Maximum number of log entries (lines) before pushing the batch in one request
LOKI_BUFFER_LINESint10000Buffer 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.

Tag summary

Content type

Image

Digest

sha256:522a4f917

Size

8.3 MB

Last updated

3 days ago

docker pull lifailon/logporter