The Problem

Customers need a single pane of glass to monitor MySQL, MongoDB, PostgreSQL, Valkey and Redis deployments, collect query‑level metrics, and receive real‑time alerts. Existing agents are scattered, and integrating them into a unified UI requires duplicated code and ad‑hoc scripts.

What This Does

The pmm repository is a portfolio of 14 loosely coupled projects that together implement Percona Monitoring and Management (PMM).

  • agent/ (≈ 242 Go source files) contains the database collectors (MySQL slow‑log, MongoDB oplog, PostgreSQL pg‑stat). Entry points such as agent/agents/mongodb/mongolog/mongodb.go expose a Run function that streams metrics to the server.
  • managed/ (≈ 411 Go files) provides the server‑side services, including telemetry, HA orchestration and alert templates (managed/services/ha/services.go).
  • ui/ (≈ 428 TSX/TS files) is a React front‑end, built with Yarn, that talks to the server via ui/apps/pmm/src/api/api.ts.
  • admin/ (admin/cmd/pmm-admin/main.go) offers a CLI for bootstrap, user management and server lifecycle.
  • qan‑api2/ implements the Query Analytics API and ships a Docker‑compose stack (qan-api2/docker-compose.yml).

Common techniques across the projects are Go modules for back‑end services, Protocol Buffers for RPC (api/agent/pb/), and a shared Docker‑based dev environment (.devcontainer/Dockerfile).

How It Is Wired

Execution starts in admin/cmd/pmm-admin/main.go (func main). It parses CLI flags, then calls Run, which reaches 70 internal functions and eventually invokes the server bootstrap in managed/services/ha/services.go. The bootstrap creates the telemetry datasource (managed/models/location_model.go) and starts the HTTP API (api/agent/pb/agent_grpc.pb.go).

On the data‑collection side, each agent binary is built from the agent/cmd/pmm-agent-entrypoint/main.go entry point. For MongoDB, Run in agent/agents/mongodb/mongolog/mongodb.go opens a DB connection (db.ExecContext), reads the oplog, and writes JSON files (os.Remove later). The call chain is short: Run → updateAllExternalExporterStatuses → hasExternalExporters → db.QueryRow.

The UI loads data via the hub module ui/apps/pmm/src/api/api.ts. Twelve other UI modules import this hub, making it the highest‑blast‑radius component (12 dependents). The hub calls the Go HTTP server’s JSON endpoints, which ultimately invoke the same Run‑style functions in the agents.

The most connected back‑end symbols are generic helpers such as Run, New, Parse, Close and ReadFile, each called from dozens of locations (e.g., Run from 98 places). No circular import cycles were detected, but deep nesting (up to 8 levels) and duplicated validation blocks (≈ 655 occurrences) increase cognitive load.

How To Use It

# Clone the repo
git clone https://github.com/moses-y/pmm
cd pmm

# Build server and agents (requires Go 1.22+ and Docker)
make -f admin/Makefile build          # builds pmm-admin binary
make -f agent/Makefile build          # builds agent binaries

# Start a dev stack (Docker Compose defined in qan-api2)
docker compose -f qan-api2/docker-compose.yml up -d

# Set required env (example) – see .env.example
export QANAPI_DSN="user:pass@tcp(localhost:3306)/qan"

# Run the admin CLI to bootstrap the server
./admin/cmd/pmm-admin/pmm-admin bootstrap

The UI can be launched with Yarn:

cd ui/apps/pmm
yarn install
yarn start

Real‑World Use

A SaaS provider deploys the PMM server container on each Kubernetes cluster. Their CI pipeline builds the agent binaries, stores them in a private registry, and runs the pmm-admin bootstrap command to provision Grafana dashboards and alert rules. Application teams then install the agent binary on each DB host; the agents push metrics to the server, which the UI visualizes for capacity planning.

Code Health & Issues

  • Critical – Committed credentials in qan-api2/.env. Rotate, remove from Git, and replace with *.example.
  • High – Same .env is tracked despite .gitignore; git rm --cached and rotate.
  • High – Untracked secret file agent/utils/tests/testdata/mongodb/*.pem. Add to .gitignore.
  • Medium – No pre‑commit secret scan; add a hook (e.g., git-secrets).
  • Medium – Large JSON fixtures (metrics.part_*.json) > 5 MiB; move to Git LFS or external storage.
  • Medium – GitHub Actions checkout persists token; set persist-credentials: false.
  • Low – Workflow jobs lack timeout-minutes; add sensible limits.
  • Low – Repository lacks standard convention files (.editorconfig, formatter config); add them.

Measured static analysis also reported 56 instances of deep nesting, 655 duplicated validation blocks, and high branching density in ui/apps/pmm/src/components/icon/Icon.constants.ts. Refactoring these hotspots will lower maintenance cost.

The Bottom Line

PMM provides a full‑stack, open‑source monitoring solution with clearly separated agent, server, and UI components. The codebase is functional but suffers from secret leakage, large binary blobs and maintainability hotspots (deep nesting, duplicated validation). Teams comfortable with Go, Docker and React can adopt it quickly, provided they address the critical credential issues and consider refactoring the identified high‑impact modules.