Skip to content

Container Monitoring

Loggator automatically discovers and monitors Docker containers based on labels, providing real-time insights into their logs and health.

Loggator connects to the Docker socket and:

  1. Discovers containers with the monitoring label
  2. Streams logs in real-time (both stdout and stderr)
  3. Indexes logs into Meilisearch
  4. Monitors container lifecycle events

When Loggator starts:

  • Scans all running containers
  • Checks for the monitoring label
  • Begins streaming logs immediately

Loggator listens for Docker events:

  • Container started: Monitoring begins automatically
  • Container stopped: Monitoring stops gracefully
  • Container recreated: Reconnects to new instance

No manual configuration required!

Only containers with the specified label are accessed:

services:
my-app:
labels:
- "loggator.enable=true" # This container will be monitored

This prevents:

  • Unauthorized access to containers
  • Accidental monitoring of sensitive services
  • Resource waste on irrelevant logs

Loggator captures both output streams:

  • Normal application logs
  • Info messages
  • Debug output
  • Access logs
  • Error messages
  • Warnings
  • Exceptions
  • Stack traces

For each log line:

  1. Timestamp Extraction: Parses Docker timestamps
  2. Stream Tagging: Labels as stdout or stderr
  3. Metadata Addition: Container name, ID, labels
  4. Batch Buffering: Groups for efficient indexing
  5. Indexing: Sends to Meilisearch
  • Latency: 5-10 seconds from log to index
  • Throughput: ~1000 logs/second
  • Batch Size: 100 logs or 5-second timeout

For each monitored container, Loggator tracks:

  • Name: Container name (without leading /)
  • ID: Full container ID
  • Short ID: First 12 characters
  • Image: Docker image and tag
  • State: running, stopped, paused, restarting
  • Status: Human-readable status message
  • Exit Code: If stopped
  • Health: Container health check status
  • Created: When container was created
  • Started: When last started
  • Finished: When stopped (if applicable)
  • Ports: Port mappings
  • Networks: Connected networks
  • IP Addresses: Per network
  • CPU: Current CPU usage (if available)
  • Memory: Current memory usage (if available)
  • Labels: All Docker labels
Terminal window
docker run -d \
--label loggator.enable=true \
--name my-app \
nginx:latest

Loggator:

  1. Detects start event
  2. Inspects container for label
  3. Begins log streaming
  4. Adds to monitored list
Terminal window
docker stop my-app

Loggator:

  1. Detects stop event
  2. Closes log stream gracefully
  3. Removes from active monitoring
  4. Historical logs remain searchable
Terminal window
docker restart my-app

Loggator:

  1. Detects stop event → closes old stream
  2. Detects start event → opens new stream
  3. Continues logging seamlessly
Terminal window
docker rm my-app

Loggator:

  1. Detects destroy event
  2. Removes from monitoring
  3. Logs remain in Meilisearch
  4. Can still be searched by name

If your container has a health check:

services:
api:
image: myapi:latest
labels:
- "loggator.enable=true"
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost/health"]
interval: 30s
timeout: 10s
retries: 3

Loggator shows health status:

  • healthy: Green indicator
  • unhealthy: Red indicator
  • starting: Yellow indicator

The AI assistant can analyze container health:

Query: "Is my api container healthy?"

Analyzes:

  • Error rate in recent logs
  • Warning patterns
  • Critical messages
  • Crash indicators

The container list shows:

  • Running: Green badge with “running” text
  • Stopped: Red badge with “exited” text
  • Status: Full Docker status string

Sort containers by:

  • Name (alphabetical)
  • Status (running first)
  • Created (newest first)
  • Log count (highest first)

Filter containers by:

  • Status (running/stopped)
  • Name (search)
  • Image (specific image)
  • Label (additional labels)

Get container information programmatically:

Terminal window
curl http://localhost:3000/api/containers
Terminal window
curl http://localhost:3000/api/containers/my-app
Terminal window
curl "http://localhost:3000/api/logs/search?container=my-app&limit=100"

See Containers API for full documentation.

Use the same label across environments:

labels:
- "loggator.enable=true"

Skip containers with:

  • High log volume (databases)
  • Sensitive data (auth services)
  • Temporary purpose (build containers)

Use extra labels for organization:

labels:
- "loggator.enable=true"
- "app=myapp"
- "tier=backend"
- "environment=production"

Add health checks to your containers:

healthcheck:
test: ["CMD-SHELL", "curl -f http://localhost:3000/health || exit 1"]
interval: 30s

Clear names help in logs: ❌ container_1, app_web_1myapp-api, myapp-web

Check:

Terminal window
# Container is running
docker ps | grep my-app
# Has correct label
docker inspect my-app | grep loggator.enable
# Loggator can access Docker socket
docker logs loggator | grep "Docker"

Verify:

Terminal window
# Container is producing logs
docker logs my-app
# Logs go to stdout/stderr (not files)
# Check application log configuration

Causes:

  • Container hasn’t logged yet
  • Logs go to files instead of stdout/stderr
  • Meilisearch indexing issue

Solutions:

  1. Trigger some application activity
  2. Configure app to log to stdout/stderr
  3. Check Meilisearch: curl http://localhost:7700/health

Cause: Container was restarted while Loggator was running

Solution: This is normal. Both old and new logs are preserved.

If monitoring many containers:

  1. Filter selectively: Only label necessary containers
  2. Increase resources: More RAM for Loggator
  3. Batch settings: Increase batch size (requires code change)
  4. Log retention: Delete old logs periodically

Change the label Loggator looks for:

loggator:
environment:
DOCKER_LABEL_FILTER: app.monitor=production

Run separate instances for different purposes:

services:
loggator-prod:
environment:
DOCKER_LABEL_FILTER: environment=production
ports:
- "3000:3000"
loggator-dev:
environment:
DOCKER_LABEL_FILTER: environment=development
ports:
- "3001:3000"

For Docker Swarm or remote Docker:

loggator:
environment:
DOCKER_HOST: tcp://remote-docker:2376
DOCKER_CERT_PATH: /certs
DOCKER_TLS_VERIFY: 1
volumes:
- ./certs:/certs:ro

Always use read-only mount:

volumes:
- /var/run/docker.sock:/var/run/docker.sock:ro

Only labeled containers are accessed:

  • Prevents information leakage
  • Reduces attack surface
  • Supports multi-tenant setups

Avoid labeling containers with:

  • Secrets or credentials
  • Personal information (PII)
  • Financial data
  • Authentication tokens