Blackbox

live · 0.0.2internal

One place to find out what my server's containers have been saying.

What it is

Blackbox is a central place to collect and search the logs from the Docker containers running on my server.

Instead of looking through one container at a time, I can search across my projects and look back at what happened, even after a container has been replaced.

Why I made it

As I’ve built out my server, I’ve ended up making tools for most of the work involved in running it. Lighthouse handles deployments, Cove handles secrets, and Sonar tells me whether everything is healthy.

But when something went wrong, I was still digging through individual containers with docker logs and trying to piece together what happened.

That works until the container gets replaced, or the error you’re looking for happened in a different service than the one you’re checking.

I wanted one place to look through that history. Not another system for controlling my server, just a record of what my applications were doing when things worked and when they didn’t.

How it works

Blackbox watches the Docker containers on my server and collects the log output they already produce. It doesn’t require every project to use a special library. If Docker has the logs, Blackbox can collect them.

It runs as three parts. A small proxy is the only part with access to Docker’s socket. A collector reads the log streams, recognizes common formats, redacts some sensitive values, and stores the results in PostgreSQL. An authenticated API makes the stored logs searchable.

Each entry can be associated with its project, service, container, and version using Docker’s metadata. From the command-line interface, I can filter by those details, search for particular messages, or pull up the lines surrounding an error.

The collector also keeps track of where it left off, so an interruption doesn’t mean starting from scratch. When Docker logs are no longer available or appear damaged, Blackbox records a gap so I can tell the history might be incomplete.

Logs are kept for up to 30 days, subject to a storage limit. Blackbox only observes and records; it doesn’t restart or change the containers it watches.

Where it’s at

Blackbox has been deployed and is already collecting real logs from my server. The collector, searchable API, and command-line tools are in place, including commands for checking collection health and investigating gaps.

The first round of work has mostly been about making collection dependable and making the stored information useful when something breaks.

Eventually, I want Vista, a dashboard I’m planning for my server, to provide a more convenient way to explore the same logs. For now, Blackbox works on its own, and the CLI is how I use it.

Changelog

0.0.2latest5 new · 2 fixes · 5 changes

added

  • Vista can use the API, with its own token in SHARED_BLACKBOX_VISTA_TOKEN and the same read access as the CLI.
  • GET /v1/stats/errors counts error and warning lines per project, per hour or day, with each project’s totals.
  • GET /v1/stats/errors/groups groups repeated lines by project, service, level and fingerprint: the message and its err field, with ids and numbers taken out. Each group has a count, when it was first and last seen, and its newest line, for context. Both endpoints cover the last 24 hours unless given a range, and at most 31 days.
  • The CLI’s errors command lists the repeated errors, most frequent first; --level warn adds warnings.
  • An MIT LICENSE.

changed

  • blackbox-api needs a token for every consumer to start, now including SHARED_BLACKBOX_VISTA_TOKEN.
  • The image runs as user 10001; only blackbox-proxy runs as root, set in the compose file, to read the Docker socket.
  • Blackbox’s start line no longer repeats its version and environment, which are read from Docker.
  • Go 1.27.4.
  • The README is rewritten, with the features, the API and every setting.

fixed

  • A service that stops on an error logs why at ERROR, instead of as plain text with no level, so searches and error counts include it.
  • A shutdown that runs past its time limit is logged instead of ignored.
0.0.12 fixes · 1 change

changed

  • The API moved to port 3190 (blackbox-api:3190 on spark), and to 3191 for local development. It stays unpublished in prod.

fixed

  • Ordinary sentences about cookies are no longer hidden: chat lines such as “Your daily cookie: …” were redacted as if they were Cookie: headers. Real cookie headers and cookie= values still are.
  • Tabs in log lines show as spaces in the CLI, not ?. Multi-line Postgres statements are readable now.
0.0.010 new

added

  • blackbox-proxy: the only part with the Docker socket. It has no network, lists containers without their environment or mounts, and passes log bytes through without reading them.
  • blackbox-collector: follows every container, running or stopped, unless it’s labelled com.mobasity.logs=off. Each line’s project, service and version come from Docker’s labels.
  • Lines are parsed from JSON, slog text, Go’s log, cloudflared and Postgres. Anything else is kept as plain text with level unknown.
  • Secrets in lines are hidden: bearer tokens, passwords in URLs, Authorization and Cookie values, and values under sensitive names.
  • Each batch of lines is saved in one transaction with its containers’ checkpoints, so a restart or an outage loses nothing and repeats nothing.
  • Known and possible loss is recorded as a gap: a container removed before it was read, the collector being down, or a Docker log damaged by a power cut.
  • Retention of 30 days, with a 1 GB cap that removes the oldest records first.
  • blackbox-api: authenticated search, single records, surrounding lines, sources, gaps and status, on blackbox-api:2600.
  • The CLI: search, show, context, status, sources, gaps, consumers, migrate status, version, help.
  • Blackbox’s own logs follow Spark’s logging standard, through blackboxlog.

all releases on GitHub

More to look at

all projects
  • Lighthouse

    live · 1.6.1internal

    I push code to GitHub, and my server takes it from there.

  • Cove

    live · 1.0.4internal

    My own little vault for the passwords, keys, and secrets my projects need.

  • CoveClient

    live · 1.0.0Go library

    One consistent way for my Go projects to communicate with Cove.